Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp @ 2152:f68f9a8d0d63 dicom-sr tip
integration mainline->dicom-sr
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 31 Aug 2024 08:40:01 +0200 |
parents | 16c01cc201e7 |
children |
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 | |
2124
16c01cc201e7
updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2114
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
2114
c23eef785569
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2077
diff
changeset
|
6 * Copyright (C) 2021-2024 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" | |
1987
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
29 #include "TextureBaseSceneLayer.h" |
1804 | 30 |
1978
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
31 #include <Images/ImageTraits.h> |
1804 | 32 #include <OrthancException.h> |
33 | |
34 #include <boost/math/constants/constants.hpp> | |
35 #include <list> | |
36 | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
37 static const double PI = boost::math::constants::pi<double>(); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
38 |
1804 | 39 static const double HANDLE_SIZE = 10.0; |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
40 static const double ARROW_LENGTH = 1.5 * HANDLE_SIZE; |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
41 static const double ARROW_ANGLE = 20.0 * PI / 180.0; |
1804 | 42 |
43 static const char* const KEY_ANNOTATIONS = "annotations"; | |
44 static const char* const KEY_TYPE = "type"; | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
45 static const char* const KEY_X = "x"; |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
46 static const char* const KEY_Y = "y"; |
1804 | 47 static const char* const KEY_X1 = "x1"; |
48 static const char* const KEY_Y1 = "y1"; | |
49 static const char* const KEY_X2 = "x2"; | |
50 static const char* const KEY_Y2 = "y2"; | |
51 static const char* const KEY_X3 = "x3"; | |
52 static const char* const KEY_Y3 = "y3"; | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
53 static const char* const KEY_UNITS = "units"; |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
54 static const char* const KEY_LABEL = "label"; |
1804 | 55 |
56 static const char* const VALUE_ANGLE = "angle"; | |
57 static const char* const VALUE_CIRCLE = "circle"; | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
58 static const char* const VALUE_LENGTH = "length"; |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
59 static const char* const VALUE_MILLIMETERS = "millimeters"; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
60 static const char* const VALUE_PIXELS = "pixels"; |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
61 static const char* const VALUE_PIXEL_PROBE = "pixel-probe"; |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
62 static const char* const VALUE_RECTANGLE_PROBE = "rectangle-probe"; |
1987
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
63 static const char* const VALUE_ELLIPSE_PROBE = "ellipse-probe"; |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
64 static const char* const VALUE_TEXT_ANNOTATION = "text"; |
1804 | 65 |
1819
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
66 #if 0 |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
67 static OrthancStone::Color COLOR_PRIMITIVES(192, 192, 192); |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
68 static OrthancStone::Color COLOR_HOVER(0, 255, 0); |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
69 static OrthancStone::Color COLOR_TEXT(255, 0, 0); |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
70 #else |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
71 static OrthancStone::Color COLOR_PRIMITIVES(0x40, 0x82, 0xad); |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
72 static OrthancStone::Color COLOR_HOVER(0x40, 0xad, 0x79); |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
73 static OrthancStone::Color COLOR_TEXT(0x4e, 0xde, 0x99); |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
74 #endif |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
75 |
1804 | 76 |
77 namespace OrthancStone | |
78 { | |
79 class AnnotationsSceneLayer::GeometricPrimitive : public boost::noncopyable | |
80 { | |
81 private: | |
82 bool modified_; | |
83 Annotation& parentAnnotation_; | |
84 Color color_; | |
85 Color hoverColor_; | |
86 bool isHover_; | |
87 int depth_; | |
88 | |
89 public: | |
90 GeometricPrimitive(Annotation& parentAnnotation, | |
91 int depth) : | |
92 modified_(true), | |
93 parentAnnotation_(parentAnnotation), | |
1819
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
94 color_(COLOR_PRIMITIVES), |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
95 hoverColor_(COLOR_HOVER), |
1804 | 96 isHover_(false), |
97 depth_(depth) | |
98 { | |
99 } | |
100 | |
101 virtual ~GeometricPrimitive() | |
102 { | |
103 } | |
104 | |
105 Annotation& GetParentAnnotation() const | |
106 { | |
107 return parentAnnotation_; | |
108 } | |
109 | |
110 int GetDepth() const | |
111 { | |
112 return depth_; | |
113 } | |
114 | |
115 void SetHover(bool hover) | |
116 { | |
117 if (hover != isHover_) | |
118 { | |
119 isHover_ = hover; | |
120 modified_ = true; | |
121 } | |
122 } | |
123 | |
124 bool IsHover() const | |
125 { | |
126 return isHover_; | |
127 } | |
128 | |
129 void SetModified(bool modified) | |
130 { | |
131 modified_ = modified; | |
132 } | |
133 | |
134 bool IsModified() const | |
135 { | |
136 return modified_; | |
137 } | |
138 | |
139 void SetColor(const Color& color) | |
140 { | |
141 SetModified(true); | |
142 color_ = color; | |
143 } | |
144 | |
145 void SetHoverColor(const Color& color) | |
146 { | |
147 SetModified(true); | |
148 hoverColor_ = color; | |
149 } | |
150 | |
151 const Color& GetColor() const | |
152 { | |
153 return color_; | |
154 } | |
155 | |
156 const Color& GetHoverColor() const | |
157 { | |
158 return hoverColor_; | |
159 } | |
1981
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
160 |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
161 Color GetActiveColor() const |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
162 { |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
163 return (IsHover() ? GetHoverColor() : GetColor()); |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
164 } |
1804 | 165 |
166 virtual bool IsHit(const ScenePoint2D& p, | |
167 const Scene2D& scene) const = 0; | |
168 | |
169 // Always called, even if not modified | |
170 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
171 const Scene2D& scene) = 0; | |
172 | |
173 // Only called if modified | |
174 virtual void RenderOtherLayers(MacroSceneLayer& macro, | |
175 const Scene2D& scene) = 0; | |
176 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
177 virtual void MovePreview(const ScenePoint2D& delta, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
178 const Scene2D& scene) = 0; |
1804 | 179 |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
180 virtual void MoveDone(const ScenePoint2D& delta, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
181 const Scene2D& scene) = 0; |
1804 | 182 }; |
183 | |
184 | |
185 class AnnotationsSceneLayer::Annotation : public boost::noncopyable | |
186 { | |
187 private: | |
188 typedef std::list<GeometricPrimitive*> GeometricPrimitives; | |
189 | |
190 AnnotationsSceneLayer& that_; | |
191 GeometricPrimitives primitives_; | |
192 | |
193 public: | |
2000 | 194 explicit Annotation(AnnotationsSceneLayer& that) : |
195 that_(that) | |
1804 | 196 { |
197 that.AddAnnotation(this); | |
198 } | |
199 | |
200 virtual ~Annotation() | |
201 { | |
202 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | |
203 { | |
204 that_.DeletePrimitive(*it); | |
205 } | |
206 } | |
207 | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
208 AnnotationsSceneLayer& GetParentLayer() const |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
209 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
210 return that_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
211 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
212 |
1804 | 213 GeometricPrimitive* AddPrimitive(GeometricPrimitive* primitive) |
214 { | |
215 if (primitive == NULL) | |
216 { | |
217 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
218 } | |
219 else | |
220 { | |
221 assert(that_.primitives_.find(primitive) == that_.primitives_.end()); | |
222 primitives_.push_back(primitive); // For automated deallocation | |
223 that_.primitives_.insert(primitive); | |
224 return primitive; | |
225 } | |
226 } | |
227 | |
228 template <typename T> | |
229 T& AddTypedPrimitive(T* primitive) | |
230 { | |
231 AddPrimitive(primitive); | |
232 return *primitive; | |
233 } | |
234 | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
235 virtual unsigned int GetHandlesCount() const = 0; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
236 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
237 virtual Handle& GetHandle(unsigned int index) const = 0; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
238 |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
239 virtual void SignalMove(GeometricPrimitive& primitive, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
240 const Scene2D& scene) = 0; |
1804 | 241 |
1976
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
242 virtual void UpdateProbe(const Scene2D& scene) = 0; |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
243 |
1804 | 244 virtual void Serialize(Json::Value& target) = 0; |
245 }; | |
246 | |
247 | |
248 class AnnotationsSceneLayer::Handle : public GeometricPrimitive | |
249 { | |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
250 public: |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
251 enum Shape { |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
252 Shape_Square, |
1981
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
253 Shape_CrossedSquare, |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
254 Shape_Circle, |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
255 Shape_CrossedCircle, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
256 Shape_Invisible /* to use in conjunction with arrows */ |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
257 }; |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
258 |
1804 | 259 private: |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
260 Shape shape_; |
1804 | 261 ScenePoint2D center_; |
262 ScenePoint2D delta_; | |
263 | |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
264 void AddCross(PolylineSceneLayer& polyline, |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
265 double x1, |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
266 double y1, |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
267 double x2, |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
268 double y2) |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
269 { |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
270 const double halfX = (x1 + x2) / 2.0; |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
271 const double halfY = (y1 + y2) / 2.0; |
1981
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
272 polyline.AddSegment(x1, halfY, x2, halfY, GetActiveColor()); |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
273 polyline.AddSegment(halfX, y1, halfX, y2, GetActiveColor()); |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
274 } |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
275 |
1804 | 276 public: |
277 explicit Handle(Annotation& parentAnnotation, | |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
278 Shape shape, |
1804 | 279 const ScenePoint2D& center) : |
280 GeometricPrimitive(parentAnnotation, 0), // Highest priority | |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
281 shape_(shape), |
1804 | 282 center_(center), |
283 delta_(0, 0) | |
284 { | |
285 } | |
286 | |
287 void SetSize(unsigned int size) | |
288 { | |
289 SetModified(true); | |
290 } | |
291 | |
292 void SetCenter(const ScenePoint2D& center) | |
293 { | |
294 SetModified(true); | |
295 center_ = center; | |
296 delta_ = ScenePoint2D(0, 0); | |
297 } | |
298 | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
299 void SetCenter(double x, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
300 double y) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
301 { |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
302 SetCenter(ScenePoint2D(x, y)); |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
303 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
304 |
1804 | 305 ScenePoint2D GetCenter() const |
306 { | |
307 return center_ + delta_; | |
308 } | |
309 | |
310 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
|
311 const Scene2D& scene) const ORTHANC_OVERRIDE |
1804 | 312 { |
313 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom(); | |
314 | |
315 double dx = (center_.GetX() + delta_.GetX() - p.GetX()) * zoom; | |
316 double dy = (center_.GetY() + delta_.GetY() - p.GetY()) * zoom; | |
317 | |
1981
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
318 return (std::abs(dx) <= HANDLE_SIZE / 2.0 && |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
319 std::abs(dy) <= HANDLE_SIZE / 2.0); |
1804 | 320 } |
321 | |
322 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
323 const Scene2D& scene) ORTHANC_OVERRIDE | |
324 { | |
1981
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
325 static unsigned int NUM_SEGMENTS = 16; |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
326 |
1804 | 327 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom(); |
328 | |
1981
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
329 // TODO: take DPI into account |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
330 const double unzoomedHandleSize = (HANDLE_SIZE / 2.0) / zoom; |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
331 const double x = center_.GetX() + delta_.GetX(); |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
332 const double y = center_.GetY() + delta_.GetY(); |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
333 const double x1 = x - unzoomedHandleSize; |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
334 const double y1 = y - unzoomedHandleSize; |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
335 const double x2 = x + unzoomedHandleSize; |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
336 const double y2 = y + unzoomedHandleSize; |
1804 | 337 |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
338 switch (shape_) |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
339 { |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
340 case Shape_Square: |
1981
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
341 polyline.AddRectangle(x1, y1, x2, y2, GetActiveColor()); |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
342 break; |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
343 |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
344 case Shape_CrossedSquare: |
1981
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
345 polyline.AddRectangle(x1, y1, x2, y2, GetActiveColor()); |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
346 AddCross(polyline, x1, y1, x2, y2); |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
347 break; |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
348 |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
349 case Shape_Circle: |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
350 polyline.AddCircle(x, y, unzoomedHandleSize, GetActiveColor(), NUM_SEGMENTS); |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
351 break; |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
352 |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
353 case Shape_CrossedCircle: |
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
354 polyline.AddCircle(x, y, unzoomedHandleSize, GetActiveColor(), NUM_SEGMENTS); |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
355 AddCross(polyline, x1, y1, x2, y2); |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
356 break; |
1804 | 357 |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
358 case Shape_Invisible: |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
359 break; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
360 |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
361 default: |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
362 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
1804 | 363 } |
364 } | |
365 | |
366 virtual void RenderOtherLayers(MacroSceneLayer& macro, | |
367 const Scene2D& scene) ORTHANC_OVERRIDE | |
368 { | |
369 } | |
370 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
371 virtual void MovePreview(const ScenePoint2D& delta, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
372 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 373 { |
374 SetModified(true); | |
375 delta_ = delta; | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
376 GetParentAnnotation().SignalMove(*this, scene); |
1804 | 377 } |
378 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
379 virtual void MoveDone(const ScenePoint2D& delta, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
380 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 381 { |
382 SetModified(true); | |
383 center_ = center_ + delta; | |
384 delta_ = ScenePoint2D(0, 0); | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
385 GetParentAnnotation().SignalMove(*this, scene); |
1804 | 386 } |
387 }; | |
388 | |
389 | |
390 class AnnotationsSceneLayer::Segment : public GeometricPrimitive | |
391 { | |
392 private: | |
393 ScenePoint2D p1_; | |
394 ScenePoint2D p2_; | |
395 ScenePoint2D delta_; | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
396 bool hasStartArrow_; |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
397 bool hasEndArrow_; |
1804 | 398 |
399 public: | |
400 Segment(Annotation& parentAnnotation, | |
401 const ScenePoint2D& p1, | |
402 const ScenePoint2D& p2) : | |
403 GeometricPrimitive(parentAnnotation, 1), // Can only be selected if no handle matches | |
404 p1_(p1), | |
405 p2_(p2), | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
406 delta_(0, 0), |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
407 hasStartArrow_(false), |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
408 hasEndArrow_(false) |
1804 | 409 { |
410 } | |
411 | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
412 Segment(Annotation& parentAnnotation, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
413 double x1, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
414 double y1, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
415 double x2, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
416 double y2) : |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
417 GeometricPrimitive(parentAnnotation, 1), // Can only be selected if no handle matches |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
418 p1_(x1, y1), |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
419 p2_(x2, y2), |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
420 delta_(0, 0), |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
421 hasStartArrow_(false), |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
422 hasEndArrow_(false) |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
423 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
424 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
425 |
1804 | 426 void SetPosition(const ScenePoint2D& p1, |
427 const ScenePoint2D& p2) | |
428 { | |
429 SetModified(true); | |
430 p1_ = p1; | |
431 p2_ = p2; | |
432 delta_ = ScenePoint2D(0, 0); | |
433 } | |
434 | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
435 void SetPosition(double x1, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
436 double y1, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
437 double x2, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
438 double y2) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
439 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
440 SetModified(true); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
441 p1_ = ScenePoint2D(x1, y1); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
442 p2_ = ScenePoint2D(x2, y2); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
443 delta_ = ScenePoint2D(0, 0); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
444 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
445 |
1804 | 446 ScenePoint2D GetPosition1() const |
447 { | |
448 return p1_ + delta_; | |
449 } | |
450 | |
451 ScenePoint2D GetPosition2() const | |
452 { | |
453 return p2_ + delta_; | |
454 } | |
455 | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
456 void SetStartArrow(bool enabled) |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
457 { |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
458 SetModified(true); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
459 hasStartArrow_ = enabled; |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
460 } |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
461 |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
462 bool HasStartArrow() const |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
463 { |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
464 return hasStartArrow_; |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
465 } |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
466 |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
467 void SetEndArrow(bool enabled) |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
468 { |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
469 SetModified(true); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
470 hasEndArrow_ = enabled; |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
471 } |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
472 |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
473 bool HasEndArrow() const |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
474 { |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
475 return hasEndArrow_; |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
476 } |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
477 |
1804 | 478 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
|
479 const Scene2D& scene) const ORTHANC_OVERRIDE |
1804 | 480 { |
481 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom(); | |
482 return (ScenePoint2D::SquaredDistancePtSegment(p1_ + delta_, p2_ + delta_, p) * zoom * zoom <= | |
483 (HANDLE_SIZE / 2.0) * (HANDLE_SIZE / 2.0)); | |
484 } | |
485 | |
486 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
487 const Scene2D& scene) ORTHANC_OVERRIDE | |
488 { | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
489 const Color color = GetActiveColor(); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
490 const ScenePoint2D a(p1_ + delta_); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
491 const ScenePoint2D b(p2_ + delta_); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
492 |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
493 polyline.AddSegment(a, b, color); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
494 |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
495 if (hasStartArrow_ || |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
496 hasEndArrow_) |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
497 { |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
498 const double length = ARROW_LENGTH / scene.GetSceneToCanvasTransform().ComputeZoom(); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
499 const double angle = atan2(b.GetY() - a.GetY(), b.GetX() - a.GetX()); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
500 |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
501 if (hasStartArrow_) |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
502 { |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
503 polyline.AddSegment(a, a + ScenePoint2D( |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
504 length * cos(angle + ARROW_ANGLE), |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
505 length * sin(angle + ARROW_ANGLE)), color); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
506 polyline.AddSegment(a, a + ScenePoint2D( |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
507 length * cos(angle - ARROW_ANGLE), |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
508 length * sin(angle - ARROW_ANGLE)), color); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
509 } |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
510 |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
511 if (hasEndArrow_) |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
512 { |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
513 polyline.AddSegment(b, b + ScenePoint2D( |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
514 length * cos(angle + ARROW_ANGLE + PI), |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
515 length * sin(angle + ARROW_ANGLE + PI)), color); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
516 polyline.AddSegment(b, b + ScenePoint2D( |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
517 length * cos(angle - ARROW_ANGLE + PI), |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
518 length * sin(angle - ARROW_ANGLE + PI)), color); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
519 } |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
520 } |
1804 | 521 } |
522 | |
523 virtual void RenderOtherLayers(MacroSceneLayer& macro, | |
524 const Scene2D& scene) ORTHANC_OVERRIDE | |
525 { | |
526 } | |
527 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
528 virtual void MovePreview(const ScenePoint2D& delta, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
529 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 530 { |
531 SetModified(true); | |
532 delta_ = delta; | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
533 GetParentAnnotation().SignalMove(*this, scene); |
1804 | 534 } |
535 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
536 virtual void MoveDone(const ScenePoint2D& delta, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
537 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 538 { |
539 SetModified(true); | |
540 p1_ = p1_ + delta; | |
541 p2_ = p2_ + delta; | |
542 delta_ = ScenePoint2D(0, 0); | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
543 GetParentAnnotation().SignalMove(*this, scene); |
1804 | 544 } |
545 }; | |
546 | |
547 | |
548 class AnnotationsSceneLayer::Circle : public GeometricPrimitive | |
549 { | |
550 private: | |
551 ScenePoint2D p1_; | |
552 ScenePoint2D p2_; | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
553 ScenePoint2D delta_; |
1804 | 554 |
555 public: | |
556 Circle(Annotation& parentAnnotation, | |
557 const ScenePoint2D& p1, | |
558 const ScenePoint2D& p2) : | |
559 GeometricPrimitive(parentAnnotation, 2), | |
560 p1_(p1), | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
561 p2_(p2), |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
562 delta_(0, 0) |
1804 | 563 { |
564 } | |
565 | |
566 void SetPosition(const ScenePoint2D& p1, | |
567 const ScenePoint2D& p2) | |
568 { | |
569 SetModified(true); | |
570 p1_ = p1; | |
571 p2_ = p2; | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
572 delta_ = ScenePoint2D(0, 0); |
1804 | 573 } |
574 | |
575 ScenePoint2D GetPosition1() const | |
576 { | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
577 return p1_ + delta_; |
1804 | 578 } |
579 | |
580 ScenePoint2D GetPosition2() const | |
581 { | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
582 return p2_ + delta_; |
1804 | 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 { |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
588 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom(); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
589 |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
590 ScenePoint2D middle((p1_.GetX() + p2_.GetX()) / 2.0, |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
591 (p1_.GetY() + p2_.GetY()) / 2.0); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
592 |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
593 const double radius = ScenePoint2D::DistancePtPt(middle, p1_); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
594 const double distance = ScenePoint2D::DistancePtPt(middle, p - delta_); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
595 |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
596 return std::abs(radius - distance) * zoom <= HANDLE_SIZE / 2.0; |
1804 | 597 } |
598 | |
599 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
600 const Scene2D& scene) ORTHANC_OVERRIDE | |
601 { | |
602 static unsigned int NUM_SEGMENTS = 128; | |
603 | |
1981
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
604 ScenePoint2D center((p1_.GetX() + p2_.GetX()) / 2.0, |
1804 | 605 (p1_.GetY() + p2_.GetY()) / 2.0); |
606 | |
1981
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
607 const double radius = ScenePoint2D::DistancePtPt(center, p1_); |
1804 | 608 |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
609 polyline.AddCircle(center.GetX() + delta_.GetX(), center.GetY() + delta_.GetY(), |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
610 radius, GetActiveColor(), NUM_SEGMENTS); |
1804 | 611 } |
612 | |
613 virtual void RenderOtherLayers(MacroSceneLayer& macro, | |
614 const Scene2D& scene) ORTHANC_OVERRIDE | |
615 { | |
616 } | |
617 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
618 virtual void MovePreview(const ScenePoint2D& delta, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
619 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 620 { |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
621 SetModified(true); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
622 delta_ = delta; |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
623 GetParentAnnotation().SignalMove(*this, scene); |
1804 | 624 } |
625 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
626 virtual void MoveDone(const ScenePoint2D& delta, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
627 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 628 { |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
629 SetModified(true); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
630 p1_ = p1_ + delta; |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
631 p2_ = p2_ + delta; |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
632 delta_ = ScenePoint2D(0, 0); |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
633 GetParentAnnotation().SignalMove(*this, scene); |
1804 | 634 } |
635 }; | |
636 | |
637 | |
638 class AnnotationsSceneLayer::Arc : public GeometricPrimitive | |
639 { | |
640 private: | |
641 ScenePoint2D start_; | |
642 ScenePoint2D middle_; | |
643 ScenePoint2D end_; | |
644 double radius_; // in pixels | |
645 | |
646 void ComputeAngles(double& fullAngle, | |
647 double& startAngle, | |
648 double& endAngle) const | |
649 { | |
650 const double x1 = start_.GetX(); | |
651 const double y1 = start_.GetY(); | |
652 const double xc = middle_.GetX(); | |
653 const double yc = middle_.GetY(); | |
654 const double x2 = end_.GetX(); | |
655 const double y2 = end_.GetY(); | |
2011
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
656 |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
657 double referenceAngle = atan2(y1 - yc, x1 - xc); |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
658 double secondAngle = atan2(y2 - yc, x2 - xc); |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
659 |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
660 secondAngle -= referenceAngle; |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
661 |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
662 while (secondAngle >= PI) |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
663 { |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
664 secondAngle -= 2.0 * PI; |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
665 } |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
666 |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
667 while (secondAngle <= -PI) |
1804 | 668 { |
2011
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
669 secondAngle += 2.0 * PI; |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
670 } |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
671 |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
672 if (secondAngle < 0) |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
673 { |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
674 startAngle = referenceAngle + secondAngle; |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
675 endAngle = referenceAngle; |
1804 | 676 } |
2011
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
677 else |
1804 | 678 { |
2011
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
679 startAngle = referenceAngle; |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
680 endAngle = referenceAngle + secondAngle; |
1804 | 681 } |
2011
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
682 |
abd4ee1648de
Fix measurement of arcs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2002
diff
changeset
|
683 fullAngle = endAngle - startAngle; |
1804 | 684 } |
685 | |
686 public: | |
687 Arc(Annotation& parentAnnotation, | |
688 const ScenePoint2D& start, | |
689 const ScenePoint2D& middle, | |
690 const ScenePoint2D& end) : | |
691 GeometricPrimitive(parentAnnotation, 2), | |
692 start_(start), | |
693 middle_(middle), | |
694 end_(end), | |
695 radius_(20) | |
696 { | |
697 } | |
698 | |
699 double GetAngle() const | |
700 { | |
701 double fullAngle, startAngle, endAngle; | |
702 ComputeAngles(fullAngle, startAngle, endAngle); | |
703 return fullAngle; | |
704 } | |
705 | |
706 void SetStart(const ScenePoint2D& p) | |
707 { | |
708 SetModified(true); | |
709 start_ = p; | |
710 } | |
711 | |
712 void SetMiddle(const ScenePoint2D& p) | |
713 { | |
714 SetModified(true); | |
715 middle_ = p; | |
716 } | |
717 | |
718 void SetEnd(const ScenePoint2D& p) | |
719 { | |
720 SetModified(true); | |
721 end_ = p; | |
722 } | |
723 | |
724 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
|
725 const Scene2D& scene) const ORTHANC_OVERRIDE |
1804 | 726 { |
727 return false; | |
728 } | |
729 | |
730 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
731 const Scene2D& scene) ORTHANC_OVERRIDE | |
732 { | |
733 static unsigned int NUM_SEGMENTS = 64; | |
734 | |
735 const double radius = radius_ / scene.GetSceneToCanvasTransform().ComputeZoom(); | |
736 | |
737 double fullAngle, startAngle, endAngle; | |
738 ComputeAngles(fullAngle, startAngle, endAngle); | |
739 | |
1981
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
740 polyline.AddArc(middle_, radius, radius, startAngle, endAngle, GetActiveColor(), NUM_SEGMENTS); |
1804 | 741 } |
742 | |
743 virtual void RenderOtherLayers(MacroSceneLayer& macro, | |
744 const Scene2D& scene) ORTHANC_OVERRIDE | |
745 { | |
746 } | |
747 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
748 virtual void MovePreview(const ScenePoint2D& delta, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
749 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 750 { |
751 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible | |
752 } | |
753 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
754 virtual void MoveDone(const ScenePoint2D& delta, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
755 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 756 { |
757 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible | |
758 } | |
759 }; | |
760 | |
761 | |
762 class AnnotationsSceneLayer::Text : public GeometricPrimitive | |
763 { | |
764 private: | |
765 AnnotationsSceneLayer& that_; | |
766 bool first_; | |
767 size_t subLayer_; | |
768 std::unique_ptr<TextSceneLayer> content_; | |
769 | |
770 public: | |
771 Text(AnnotationsSceneLayer& that, | |
772 Annotation& parentAnnotation) : | |
773 GeometricPrimitive(parentAnnotation, 2), | |
774 that_(that), | |
1817 | 775 first_(true), |
776 subLayer_(0) // dummy initialization | |
1804 | 777 { |
778 } | |
779 | |
780 virtual ~Text() | |
781 { | |
782 if (!first_) | |
783 { | |
784 that_.TagSubLayerToRemove(subLayer_); | |
785 } | |
786 } | |
787 | |
788 void SetContent(const TextSceneLayer& content) | |
789 { | |
790 SetModified(true); | |
791 content_.reset(dynamic_cast<TextSceneLayer*>(content.Clone())); | |
1977 | 792 } |
793 | |
794 void SetText(const std::string& text) | |
795 { | |
796 if (content_.get() == NULL) | |
797 { | |
798 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
799 } | |
800 else | |
801 { | |
802 SetModified(true); | |
803 content_->SetText(text); | |
804 } | |
805 } | |
806 | |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
807 std::string GetText() const |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
808 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
809 return content_->GetText(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
810 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
811 |
1977 | 812 void SetPosition(double x, |
813 double y) | |
814 { | |
815 if (content_.get() == NULL) | |
816 { | |
817 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
818 } | |
819 else | |
820 { | |
821 SetModified(true); | |
822 content_->SetPosition(x, y); | |
823 } | |
824 } | |
1804 | 825 |
826 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
|
827 const Scene2D& scene) const ORTHANC_OVERRIDE |
1804 | 828 { |
829 return false; | |
830 } | |
831 | |
832 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
833 const Scene2D& scene) ORTHANC_OVERRIDE | |
834 { | |
835 } | |
836 | |
837 virtual void RenderOtherLayers(MacroSceneLayer& macro, | |
838 const Scene2D& scene) ORTHANC_OVERRIDE | |
839 { | |
840 if (content_.get() != NULL) | |
841 { | |
842 std::unique_ptr<TextSceneLayer> layer(reinterpret_cast<TextSceneLayer*>(content_->Clone())); | |
843 | |
1981
c074c75cf416
moved drawing primitives from AnnotationsSceneLayer to PolylineSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1980
diff
changeset
|
844 layer->SetColor(GetActiveColor()); |
1804 | 845 |
846 if (first_) | |
847 { | |
848 subLayer_ = macro.AddLayer(layer.release()); | |
849 first_ = false; | |
850 } | |
851 else | |
852 { | |
853 macro.UpdateLayer(subLayer_, layer.release()); | |
854 } | |
855 } | |
856 } | |
857 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
858 virtual void MovePreview(const ScenePoint2D& delta, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
859 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 860 { |
861 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible | |
862 } | |
863 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
864 virtual void MoveDone(const ScenePoint2D& delta, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
865 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 866 { |
867 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible | |
868 } | |
869 }; | |
870 | |
871 | |
1987
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
872 class AnnotationsSceneLayer::Ellipse : public GeometricPrimitive |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
873 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
874 private: |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
875 ScenePoint2D p1_; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
876 ScenePoint2D p2_; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
877 ScenePoint2D delta_; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
878 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
879 double GetCenterX() const |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
880 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
881 return (p1_.GetX() + p2_.GetX()) / 2.0 + delta_.GetX(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
882 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
883 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
884 double GetCenterY() const |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
885 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
886 return (p1_.GetY() + p2_.GetY()) / 2.0 + delta_.GetY(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
887 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
888 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
889 double GetRadiusX() const |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
890 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
891 return std::abs(p1_.GetX() - p2_.GetX()) / 2.0; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
892 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
893 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
894 double GetRadiusY() const |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
895 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
896 return std::abs(p1_.GetY() - p2_.GetY()) / 2.0; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
897 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
898 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
899 public: |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
900 Ellipse(Annotation& parentAnnotation, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
901 const ScenePoint2D& p1, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
902 const ScenePoint2D& p2) : |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
903 GeometricPrimitive(parentAnnotation, 2), |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
904 p1_(p1), |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
905 p2_(p2), |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
906 delta_(0, 0) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
907 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
908 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
909 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
910 void SetPosition(const ScenePoint2D& p1, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
911 const ScenePoint2D& p2) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
912 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
913 SetModified(true); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
914 p1_ = p1; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
915 p2_ = p2; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
916 delta_ = ScenePoint2D(0, 0); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
917 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
918 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
919 ScenePoint2D GetPosition1() const |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
920 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
921 return p1_ + delta_; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
922 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
923 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
924 ScenePoint2D GetPosition2() const |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
925 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
926 return p2_ + delta_; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
927 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
928 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
929 double GetArea() const |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
930 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
931 return PI * GetRadiusX() * GetRadiusY(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
932 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
933 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
934 bool IsPointInside(const ScenePoint2D& p) const |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
935 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
936 const double radiusX = GetRadiusX(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
937 const double radiusY = GetRadiusY(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
938 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
939 double a, b, x, y; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
940 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
941 if (radiusX > radiusY) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
942 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
943 // The ellipse is horizontal => we are in the case described |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
944 // on Wikipedia: |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
945 // https://en.wikipedia.org/wiki/Ellipse#Standard_equation |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
946 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
947 a = radiusX; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
948 b = radiusY; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
949 x = p.GetX() - GetCenterX(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
950 y = p.GetY() - GetCenterY(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
951 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
952 else |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
953 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
954 a = radiusY; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
955 b = radiusX; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
956 x = p.GetY() - GetCenterY(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
957 y = p.GetX() - GetCenterX(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
958 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
959 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
960 const double c = sqrt(a * a - b * b); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
961 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
962 return (sqrt((x - c) * (x - c) + y * y) + |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
963 sqrt((x + c) * (x + c) + y * y)) <= 2.0 * a; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
964 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
965 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
966 virtual bool IsHit(const ScenePoint2D& p, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
967 const Scene2D& scene) const ORTHANC_OVERRIDE |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
968 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
969 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
970 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
971 const double radiusX = GetRadiusX(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
972 const double radiusY = GetRadiusY(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
973 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
974 // Warning: This is only an approximation of the |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
975 // point-to-ellipse distance, as explained here: |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
976 // https://blog.chatfield.io/simple-method-for-distance-to-ellipse/ |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
977 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
978 const double x = (p.GetX() - GetCenterX()) / radiusX; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
979 const double y = (p.GetY() - GetCenterY()) / radiusY; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
980 const double t = atan2(y, x); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
981 const double xx = cos(t) - x; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
982 const double yy = sin(t) - y; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
983 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
984 const double approximateDistance = sqrt(xx * xx + yy * yy) * (radiusX + radiusY) / 2.0; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
985 return std::abs(approximateDistance) * zoom <= HANDLE_SIZE / 2.0; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
986 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
987 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
988 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
989 const Scene2D& scene) ORTHANC_OVERRIDE |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
990 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
991 static unsigned int NUM_SEGMENTS = 128; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
992 polyline.AddArc(GetCenterX(), GetCenterY(), GetRadiusX(), GetRadiusY(), 0, 2.0 * PI, GetActiveColor(), NUM_SEGMENTS); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
993 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
994 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
995 virtual void RenderOtherLayers(MacroSceneLayer& macro, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
996 const Scene2D& scene) ORTHANC_OVERRIDE |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
997 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
998 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
999 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1000 virtual void MovePreview(const ScenePoint2D& delta, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1001 const Scene2D& scene) ORTHANC_OVERRIDE |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1002 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1003 SetModified(true); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1004 delta_ = delta; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1005 GetParentAnnotation().SignalMove(*this, scene); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1006 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1007 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1008 virtual void MoveDone(const ScenePoint2D& delta, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1009 const Scene2D& scene) ORTHANC_OVERRIDE |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1010 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1011 SetModified(true); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1012 p1_ = p1_ + delta; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1013 p2_ = p2_ + delta; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1014 delta_ = ScenePoint2D(0, 0); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1015 GetParentAnnotation().SignalMove(*this, scene); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1016 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1017 }; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1018 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1019 |
1804 | 1020 class AnnotationsSceneLayer::EditPrimitiveTracker : public IFlexiblePointerTracker |
1021 { | |
1022 private: | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1023 AnnotationsSceneLayer& that_; |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1024 GeometricPrimitive& primitive_; |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1025 ScenePoint2D sceneClick_; |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1026 AffineTransform2D canvasToScene_; |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1027 bool alive_; |
1804 | 1028 |
1029 public: | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1030 EditPrimitiveTracker(AnnotationsSceneLayer& that, |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1031 GeometricPrimitive& primitive, |
1804 | 1032 const ScenePoint2D& sceneClick, |
1033 const AffineTransform2D& canvasToScene) : | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1034 that_(that), |
1804 | 1035 primitive_(primitive), |
1036 sceneClick_(sceneClick), | |
1037 canvasToScene_(canvasToScene), | |
1038 alive_(true) | |
1039 { | |
1040 } | |
1041 | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
1042 virtual void PointerMove(const PointerEvent& event, |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
1043 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 1044 { |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1045 primitive_.MovePreview(event.GetMainPosition().Apply(canvasToScene_) - sceneClick_, scene); |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1046 that_.BroadcastMessage(AnnotationChangedMessage(that_)); |
1804 | 1047 } |
1048 | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
1049 virtual void PointerUp(const PointerEvent& event, |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
1050 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 1051 { |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1052 primitive_.MoveDone(event.GetMainPosition().Apply(canvasToScene_) - sceneClick_, scene); |
1804 | 1053 alive_ = false; |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1054 that_.BroadcastMessage(AnnotationChangedMessage(that_)); |
1804 | 1055 } |
1056 | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
1057 virtual void PointerDown(const PointerEvent& event, |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
1058 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 1059 { |
1060 } | |
1061 | |
1062 virtual bool IsAlive() const ORTHANC_OVERRIDE | |
1063 { | |
1064 return alive_; | |
1065 } | |
1066 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1067 virtual void Cancel(const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 1068 { |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1069 //primitive_.MoveDone(ScenePoint2D(0, 0), scene); |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1070 primitive_.MoveDone(sceneClick_, scene); // TODO Check this |
1804 | 1071 } |
1072 }; | |
1073 | |
1074 | |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1075 class AnnotationsSceneLayer::SegmentAnnotation : public Annotation |
1804 | 1076 { |
1077 private: | |
1078 Handle& handle1_; | |
1079 Handle& handle2_; | |
1080 Segment& segment_; | |
1081 Text& label_; | |
1082 | |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1083 protected: |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1084 void SetLabelContent(const TextSceneLayer& content) |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1085 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1086 label_.SetContent(content); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1087 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1088 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1089 std::string GetCurrentLabel() const |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1090 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1091 return label_.GetText(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1092 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1093 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1094 const Handle& GetHandle1() const |
1804 | 1095 { |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1096 return handle1_; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1097 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1098 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1099 const Handle& GetHandle2() const |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1100 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1101 return handle2_; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1102 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1103 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1104 void SetStartArrow(bool enabled) |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1105 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1106 segment_.SetStartArrow(enabled); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1107 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1108 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1109 void SetEndArrow(bool enabled) |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1110 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1111 segment_.SetEndArrow(enabled); |
1804 | 1112 } |
1113 | |
1114 public: | |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1115 SegmentAnnotation(AnnotationsSceneLayer& that, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1116 Handle::Shape shape1, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1117 const ScenePoint2D& p1, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1118 Handle::Shape shape2, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1119 const ScenePoint2D& p2) : |
2000 | 1120 Annotation(that), |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1121 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, shape1, p1))), |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1122 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, shape2, p2))), |
1804 | 1123 segment_(AddTypedPrimitive<Segment>(new Segment(*this, p1, p2))), |
1124 label_(AddTypedPrimitive<Text>(new Text(that, *this))) | |
1125 { | |
1819
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
1126 label_.SetColor(COLOR_TEXT); |
1804 | 1127 } |
1128 | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1129 virtual unsigned int GetHandlesCount() const ORTHANC_OVERRIDE |
1804 | 1130 { |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1131 return 2; |
1804 | 1132 } |
1133 | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1134 virtual Handle& GetHandle(unsigned int index) const ORTHANC_OVERRIDE |
1804 | 1135 { |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1136 switch (index) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1137 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1138 case 0: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1139 return handle1_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1140 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1141 case 1: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1142 return handle2_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1143 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1144 default: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1145 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1146 } |
1804 | 1147 } |
1148 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1149 virtual void SignalMove(GeometricPrimitive& primitive, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1150 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 1151 { |
1152 if (&primitive == &handle1_ || | |
1153 &primitive == &handle2_) | |
1154 { | |
1155 segment_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter()); | |
1156 } | |
1157 else if (&primitive == &segment_) | |
1158 { | |
1159 handle1_.SetCenter(segment_.GetPosition1()); | |
1160 handle2_.SetCenter(segment_.GetPosition2()); | |
1161 } | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1162 else |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1163 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1164 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1165 } |
1804 | 1166 } |
1167 | |
1976
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1168 virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1169 { |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1170 } |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1171 }; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1172 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1173 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1174 class AnnotationsSceneLayer::LengthAnnotation : public SegmentAnnotation |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1175 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1176 private: |
2000 | 1177 Units units_; |
1178 bool showLabel_; | |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1179 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1180 void UpdateLabel() |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1181 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1182 if (showLabel_) |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1183 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1184 TextSceneLayer content; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1185 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1186 double x1 = GetHandle1().GetCenter().GetX(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1187 double y1 = GetHandle1().GetCenter().GetY(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1188 double x2 = GetHandle2().GetCenter().GetX(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1189 double y2 = GetHandle2().GetCenter().GetY(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1190 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1191 // Put the label to the right of the right-most handle |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1192 if (x1 < x2) |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1193 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1194 content.SetPosition(x2, y2); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1195 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1196 else |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1197 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1198 content.SetPosition(x1, y1); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1199 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1200 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1201 content.SetAnchor(BitmapAnchor_CenterLeft); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1202 content.SetBorder(10); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1203 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1204 double dx = x1 - x2; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1205 double dy = y1 - y2; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1206 char buf[32]; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1207 |
2000 | 1208 switch (units_) |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1209 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1210 case Units_Millimeters: |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1211 sprintf(buf, "%0.2f cm", sqrt(dx * dx + dy * dy) / 10.0); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1212 break; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1213 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1214 case Units_Pixels: |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1215 sprintf(buf, "%0.1f px", sqrt(dx * dx + dy * dy)); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1216 break; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1217 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1218 default: |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1219 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1220 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1221 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1222 content.SetText(buf); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1223 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1224 SetLabelContent(content); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1225 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1226 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1227 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1228 public: |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1229 LengthAnnotation(AnnotationsSceneLayer& that, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1230 Units units, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1231 bool showLabel, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1232 const ScenePoint2D& p1, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1233 const ScenePoint2D& p2) : |
2000 | 1234 SegmentAnnotation(that, Handle::Shape_Square, p1, Handle::Shape_Square, p2), |
1235 units_(units), | |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1236 showLabel_(showLabel) |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1237 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1238 UpdateLabel(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1239 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1240 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1241 virtual void SignalMove(GeometricPrimitive& primitive, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1242 const Scene2D& scene) ORTHANC_OVERRIDE |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1243 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1244 SegmentAnnotation::SignalMove(primitive, scene); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1245 UpdateLabel(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1246 } |
1976
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1247 |
1804 | 1248 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE |
1249 { | |
1250 target = Json::objectValue; | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
1251 target[KEY_TYPE] = VALUE_LENGTH; |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1252 target[KEY_X1] = GetHandle1().GetCenter().GetX(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1253 target[KEY_Y1] = GetHandle1().GetCenter().GetY(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1254 target[KEY_X2] = GetHandle2().GetCenter().GetX(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1255 target[KEY_Y2] = GetHandle2().GetCenter().GetY(); |
1804 | 1256 } |
1257 | |
1258 static void Unserialize(AnnotationsSceneLayer& target, | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1259 Units units, |
1804 | 1260 const Json::Value& source) |
1261 { | |
1262 if (source.isMember(KEY_X1) && | |
1263 source.isMember(KEY_Y1) && | |
1264 source.isMember(KEY_X2) && | |
1265 source.isMember(KEY_Y2) && | |
1266 source[KEY_X1].isNumeric() && | |
1267 source[KEY_Y1].isNumeric() && | |
1268 source[KEY_X2].isNumeric() && | |
1269 source[KEY_Y2].isNumeric()) | |
1270 { | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
1271 new LengthAnnotation(target, units, true, |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
1272 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
1273 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble())); |
1804 | 1274 } |
1275 else | |
1276 { | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
1277 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize a length annotation"); |
1804 | 1278 } |
1279 } | |
1280 }; | |
1281 | |
1977 | 1282 |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1283 class AnnotationsSceneLayer::TextAnnotation : public SegmentAnnotation |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1284 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1285 public: |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1286 TextAnnotation(AnnotationsSceneLayer& that, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1287 const std::string& label, |
2001
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1288 const ScenePoint2D& pointedPosition, |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1289 const ScenePoint2D& labelPosition) : |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1290 SegmentAnnotation(that, Handle::Shape_Invisible, pointedPosition /* p1 */, |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1291 Handle::Shape_Square, labelPosition /* p2 */) |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1292 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1293 SetStartArrow(true); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1294 UpdateLabel(label); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1295 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1296 |
2001
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1297 ScenePoint2D GetPointedPosition() const |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1298 { |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1299 return GetHandle1().GetCenter(); |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1300 } |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1301 |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1302 ScenePoint2D GetLabelPosition() const |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1303 { |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1304 return GetHandle2().GetCenter(); |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1305 } |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
1306 |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1307 void UpdateLabel(const std::string& label) |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1308 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1309 TextSceneLayer content; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1310 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1311 double x1 = GetHandle1().GetCenter().GetX(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1312 double x2 = GetHandle2().GetCenter().GetX(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1313 double y2 = GetHandle2().GetCenter().GetY(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1314 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1315 if (x1 < x2) |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1316 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1317 content.SetAnchor(BitmapAnchor_CenterLeft); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1318 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1319 else |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1320 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1321 content.SetAnchor(BitmapAnchor_CenterRight); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1322 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1323 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1324 content.SetPosition(x2, y2); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1325 content.SetBorder(10); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1326 content.SetText(label); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1327 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1328 SetLabelContent(content); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1329 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1330 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1331 void UpdateLabel() |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1332 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1333 UpdateLabel(GetCurrentLabel()); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1334 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1335 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1336 virtual void SignalMove(GeometricPrimitive& primitive, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1337 const Scene2D& scene) ORTHANC_OVERRIDE |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1338 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1339 SegmentAnnotation::SignalMove(primitive, scene); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1340 UpdateLabel(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1341 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1342 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1343 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1344 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1345 target = Json::objectValue; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1346 target[KEY_TYPE] = VALUE_TEXT_ANNOTATION; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1347 target[KEY_X1] = GetHandle1().GetCenter().GetX(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1348 target[KEY_Y1] = GetHandle1().GetCenter().GetY(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1349 target[KEY_X2] = GetHandle2().GetCenter().GetX(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1350 target[KEY_Y2] = GetHandle2().GetCenter().GetY(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1351 target[KEY_LABEL] = GetCurrentLabel(); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1352 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1353 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1354 static void Unserialize(AnnotationsSceneLayer& target, |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1355 const Json::Value& source) |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1356 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1357 if (source.isMember(KEY_X1) && |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1358 source.isMember(KEY_Y1) && |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1359 source.isMember(KEY_X2) && |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1360 source.isMember(KEY_Y2) && |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1361 source.isMember(KEY_LABEL) && |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1362 source[KEY_X1].isNumeric() && |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1363 source[KEY_Y1].isNumeric() && |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1364 source[KEY_X2].isNumeric() && |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1365 source[KEY_Y2].isNumeric() && |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1366 source[KEY_LABEL].isString()) |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1367 { |
2000 | 1368 new TextAnnotation(target, source[KEY_LABEL].asString(), |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1369 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1370 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble())); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1371 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1372 else |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1373 { |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1374 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize a text annotation"); |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1375 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1376 } |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1377 }; |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1378 |
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
1379 |
1978
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1380 // Use this class to avoid unnecessary probing if neither the scene, |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1381 // nor the probe, has changed |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1382 class AnnotationsSceneLayer::ProbingAnnotation : public Annotation |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1383 { |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1384 private: |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1385 int probedLayer_; |
1978
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1386 bool probeChanged_; |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1387 uint64_t lastLayerRevision_; |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1388 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1389 protected: |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1390 virtual void UpdateProbeForLayer(const ISceneLayer& layer) = 0; |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1391 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1392 void TagProbeAsChanged() |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1393 { |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1394 probeChanged_ = true; |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1395 } |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1396 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1397 public: |
2002 | 1398 explicit ProbingAnnotation(AnnotationsSceneLayer& that) : |
2000 | 1399 Annotation(that), |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1400 probedLayer_(that.GetProbedLayer()), |
1978
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1401 probeChanged_(true), |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1402 lastLayerRevision_(0) |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1403 { |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1404 } |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1405 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1406 virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1407 { |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1408 if (scene.HasLayer(probedLayer_)) |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1409 { |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1410 const ISceneLayer& layer = scene.GetLayer(probedLayer_); |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1411 if (probeChanged_ || |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1412 layer.GetRevision() != lastLayerRevision_) |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1413 { |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1414 UpdateProbeForLayer(layer); |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1415 probeChanged_ = false; |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1416 lastLayerRevision_ = layer.GetRevision(); |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1417 } |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1418 } |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1419 } |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1420 }; |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1421 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1422 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1423 class AnnotationsSceneLayer::PixelProbeAnnotation : public ProbingAnnotation |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1424 { |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1425 private: |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1426 Handle& handle_; |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1427 Text& label_; |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1428 |
1978
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1429 protected: |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1430 virtual void UpdateProbeForLayer(const ISceneLayer& layer) ORTHANC_OVERRIDE |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1431 { |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1432 if (layer.GetType() == ISceneLayer::Type_FloatTexture || |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1433 layer.GetType() == ISceneLayer::Type_ColorTexture) |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1434 { |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1435 const TextureBaseSceneLayer& texture = dynamic_cast<const TextureBaseSceneLayer&>(layer); |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1436 const AffineTransform2D sceneToTexture = AffineTransform2D::Invert(texture.GetTransform()); |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1437 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1438 double sceneX = handle_.GetCenter().GetX(); |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1439 double sceneY = handle_.GetCenter().GetY(); |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1440 sceneToTexture.Apply(sceneX, sceneY); |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1441 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1442 int x = static_cast<int>(std::floor(sceneX)); |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1443 int y = static_cast<int>(std::floor(sceneY)); |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1444 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1445 const Orthanc::ImageAccessor& image = texture.GetTexture(); |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1446 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1447 if (x >= 0 && |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1448 y >= 0 && |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1449 x < static_cast<int>(image.GetWidth()) && |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1450 y < static_cast<int>(image.GetHeight())) |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1451 { |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1452 char buf[64]; |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1453 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1454 switch (image.GetFormat()) |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1455 { |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1456 case Orthanc::PixelFormat_Float32: |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
1457 sprintf(buf, "(%d,%d): %.01f", x, y, Orthanc::ImageTraits<Orthanc::PixelFormat_Float32>::GetFloatPixel( |
1978
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1458 image, static_cast<unsigned int>(x), static_cast<unsigned int>(y))); |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1459 break; |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1460 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1461 case Orthanc::PixelFormat_RGB24: |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1462 { |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1463 Orthanc::PixelTraits<Orthanc::PixelFormat_RGB24>::PixelType pixel; |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1464 Orthanc::ImageTraits<Orthanc::PixelFormat_RGB24>::GetPixel( |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1465 pixel, image, static_cast<unsigned int>(x), static_cast<unsigned int>(y)); |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
1466 sprintf(buf, "(%d,%d): (%d,%d,%d)", x, y, pixel.red_, pixel.green_, pixel.blue_); |
1978
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1467 break; |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1468 } |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1469 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1470 default: |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1471 break; |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1472 } |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1473 |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1474 label_.SetText(buf); |
1979 | 1475 } |
1476 else | |
1477 { | |
1478 label_.SetText("?"); | |
1479 } | |
1978
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1480 } |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1481 } |
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1482 |
1976
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1483 public: |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1484 PixelProbeAnnotation(AnnotationsSceneLayer& that, |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1485 const ScenePoint2D& p) : |
2000 | 1486 ProbingAnnotation(that), |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
1487 handle_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_CrossedSquare, p))), |
1976
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1488 label_(AddTypedPrimitive<Text>(new Text(that, *this))) |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1489 { |
1977 | 1490 TextSceneLayer content; |
1491 content.SetPosition(handle_.GetCenter().GetX(), handle_.GetCenter().GetY()); | |
1492 content.SetAnchor(BitmapAnchor_CenterLeft); | |
1493 content.SetBorder(10); | |
1494 content.SetText("?"); | |
1495 | |
1496 label_.SetContent(content); | |
1976
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1497 label_.SetColor(COLOR_TEXT); |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1498 } |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1499 |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1500 virtual unsigned int GetHandlesCount() const ORTHANC_OVERRIDE |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1501 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1502 return 1; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1503 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1504 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1505 virtual Handle& GetHandle(unsigned int index) const ORTHANC_OVERRIDE |
1976
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1506 { |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1507 if (index == 0) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1508 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1509 return handle_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1510 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1511 else |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1512 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1513 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1514 } |
1976
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1515 } |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1516 |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1517 virtual void SignalMove(GeometricPrimitive& primitive, |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1518 const Scene2D& scene) ORTHANC_OVERRIDE |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1519 { |
1977 | 1520 label_.SetPosition(handle_.GetCenter().GetX(), handle_.GetCenter().GetY()); |
1978
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
1521 TagProbeAsChanged(); |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1522 } |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1523 |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1524 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1525 { |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1526 target = Json::objectValue; |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1527 target[KEY_TYPE] = VALUE_PIXEL_PROBE; |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1528 target[KEY_X] = handle_.GetCenter().GetX(); |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1529 target[KEY_Y] = handle_.GetCenter().GetY(); |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1530 } |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1531 |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1532 static void Unserialize(AnnotationsSceneLayer& target, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1533 const Json::Value& source) |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1534 { |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1535 if (source.isMember(KEY_X) && |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1536 source.isMember(KEY_Y) && |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1537 source[KEY_X].isNumeric() && |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1538 source[KEY_Y].isNumeric()) |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1539 { |
2000 | 1540 new PixelProbeAnnotation(target, ScenePoint2D(source[KEY_X].asDouble(), source[KEY_Y].asDouble())); |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1541 } |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1542 else |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1543 { |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1544 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize a pixel probe"); |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1545 } |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1546 } |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1547 }; |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1548 |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1549 |
1804 | 1550 class AnnotationsSceneLayer::AngleAnnotation : public Annotation |
1551 { | |
1552 private: | |
1553 Handle& startHandle_; | |
1554 Handle& middleHandle_; | |
1555 Handle& endHandle_; | |
1556 Segment& segment1_; | |
1557 Segment& segment2_; | |
1558 Arc& arc_; | |
1559 Text& label_; | |
1560 | |
1561 void UpdateLabel() | |
1562 { | |
1563 TextSceneLayer content; | |
1564 | |
1565 const double x1 = startHandle_.GetCenter().GetX(); | |
1566 const double x2 = middleHandle_.GetCenter().GetX(); | |
1567 const double y2 = middleHandle_.GetCenter().GetY(); | |
1568 const double x3 = endHandle_.GetCenter().GetX(); | |
1569 | |
1570 if (x2 < x1 && | |
1571 x2 < x3) | |
1572 { | |
1573 content.SetAnchor(BitmapAnchor_CenterRight); | |
1574 } | |
1575 else | |
1576 { | |
1577 content.SetAnchor(BitmapAnchor_CenterLeft); | |
1578 } | |
1579 | |
1580 content.SetPosition(x2, y2); | |
1581 content.SetBorder(10); | |
1582 | |
1583 char buf[32]; | |
1584 sprintf(buf, "%.01f%c%c", std::abs(arc_.GetAngle()) / PI * 180.0, | |
1585 0xc2, 0xb0 /* two bytes corresponding to degree symbol in UTF-8 */); | |
1586 content.SetText(buf); | |
1587 | |
1588 label_.SetContent(content); | |
1589 } | |
1590 | |
1591 public: | |
1592 AngleAnnotation(AnnotationsSceneLayer& that, | |
1593 const ScenePoint2D& start, | |
1594 const ScenePoint2D& middle, | |
1595 const ScenePoint2D& end) : | |
2000 | 1596 Annotation(that), |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
1597 startHandle_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, start))), |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
1598 middleHandle_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, middle))), |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
1599 endHandle_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, end))), |
1804 | 1600 segment1_(AddTypedPrimitive<Segment>(new Segment(*this, start, middle))), |
1601 segment2_(AddTypedPrimitive<Segment>(new Segment(*this, middle, end))), | |
1602 arc_(AddTypedPrimitive<Arc>(new Arc(*this, start, middle, end))), | |
1603 label_(AddTypedPrimitive<Text>(new Text(that, *this))) | |
1604 { | |
1819
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
1605 label_.SetColor(COLOR_TEXT); |
1804 | 1606 UpdateLabel(); |
1607 } | |
1608 | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1609 virtual unsigned int GetHandlesCount() const ORTHANC_OVERRIDE |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1610 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1611 return 3; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1612 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1613 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1614 virtual Handle& GetHandle(unsigned int index) const ORTHANC_OVERRIDE |
1804 | 1615 { |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1616 switch (index) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1617 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1618 case 0: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1619 return startHandle_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1620 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1621 case 1: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1622 return middleHandle_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1623 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1624 case 2: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1625 return endHandle_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1626 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1627 default: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1628 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1629 } |
1804 | 1630 } |
1631 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1632 virtual void SignalMove(GeometricPrimitive& primitive, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1633 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 1634 { |
1635 if (&primitive == &startHandle_) | |
1636 { | |
1637 segment1_.SetPosition(startHandle_.GetCenter(), middleHandle_.GetCenter()); | |
1638 arc_.SetStart(startHandle_.GetCenter()); | |
1639 } | |
1640 else if (&primitive == &middleHandle_) | |
1641 { | |
1642 segment1_.SetPosition(startHandle_.GetCenter(), middleHandle_.GetCenter()); | |
1643 segment2_.SetPosition(middleHandle_.GetCenter(), endHandle_.GetCenter()); | |
1644 arc_.SetMiddle(middleHandle_.GetCenter()); | |
1645 } | |
1646 else if (&primitive == &endHandle_) | |
1647 { | |
1648 segment2_.SetPosition(middleHandle_.GetCenter(), endHandle_.GetCenter()); | |
1649 arc_.SetEnd(endHandle_.GetCenter()); | |
1650 } | |
1651 else if (&primitive == &segment1_) | |
1652 { | |
1653 startHandle_.SetCenter(segment1_.GetPosition1()); | |
1654 middleHandle_.SetCenter(segment1_.GetPosition2()); | |
1655 segment2_.SetPosition(segment1_.GetPosition2(), segment2_.GetPosition2()); | |
1656 arc_.SetStart(segment1_.GetPosition1()); | |
1657 arc_.SetMiddle(segment1_.GetPosition2()); | |
1658 } | |
1659 else if (&primitive == &segment2_) | |
1660 { | |
1661 middleHandle_.SetCenter(segment2_.GetPosition1()); | |
1662 endHandle_.SetCenter(segment2_.GetPosition2()); | |
1663 segment1_.SetPosition(segment1_.GetPosition1(), segment2_.GetPosition1()); | |
1664 arc_.SetMiddle(segment2_.GetPosition1()); | |
1665 arc_.SetEnd(segment2_.GetPosition2()); | |
1666 } | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1667 else |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1668 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1669 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1670 } |
1804 | 1671 |
1672 UpdateLabel(); | |
1673 } | |
1674 | |
1976
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1675 virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1676 { |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1677 } |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1678 |
1804 | 1679 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE |
1680 { | |
1681 target = Json::objectValue; | |
1682 target[KEY_TYPE] = VALUE_ANGLE; | |
1683 target[KEY_X1] = startHandle_.GetCenter().GetX(); | |
1684 target[KEY_Y1] = startHandle_.GetCenter().GetY(); | |
1685 target[KEY_X2] = middleHandle_.GetCenter().GetX(); | |
1686 target[KEY_Y2] = middleHandle_.GetCenter().GetY(); | |
1687 target[KEY_X3] = endHandle_.GetCenter().GetX(); | |
1688 target[KEY_Y3] = endHandle_.GetCenter().GetY(); | |
1689 } | |
1690 | |
1691 static void Unserialize(AnnotationsSceneLayer& target, | |
1692 const Json::Value& source) | |
1693 { | |
1694 if (source.isMember(KEY_X1) && | |
1695 source.isMember(KEY_Y1) && | |
1696 source.isMember(KEY_X2) && | |
1697 source.isMember(KEY_Y2) && | |
1698 source.isMember(KEY_X3) && | |
1699 source.isMember(KEY_Y3) && | |
1700 source[KEY_X1].isNumeric() && | |
1701 source[KEY_Y1].isNumeric() && | |
1702 source[KEY_X2].isNumeric() && | |
1703 source[KEY_Y2].isNumeric() && | |
1704 source[KEY_X3].isNumeric() && | |
1705 source[KEY_Y3].isNumeric()) | |
1706 { | |
2000 | 1707 new AngleAnnotation(target, |
1804 | 1708 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), |
1709 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble()), | |
1710 ScenePoint2D(source[KEY_X3].asDouble(), source[KEY_Y3].asDouble())); | |
1711 } | |
1712 else | |
1713 { | |
1714 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an angle annotation"); | |
1715 } | |
1716 } | |
1717 }; | |
1718 | |
1719 | |
1720 class AnnotationsSceneLayer::CircleAnnotation : public Annotation | |
1721 { | |
1722 private: | |
2000 | 1723 Units units_; |
1804 | 1724 Handle& handle1_; |
1725 Handle& handle2_; | |
1726 Segment& segment_; | |
1727 Circle& circle_; | |
1728 Text& label_; | |
1729 | |
1730 void UpdateLabel() | |
1731 { | |
1732 TextSceneLayer content; | |
1733 | |
1734 double x1 = handle1_.GetCenter().GetX(); | |
1735 double y1 = handle1_.GetCenter().GetY(); | |
1736 double x2 = handle2_.GetCenter().GetX(); | |
1737 double y2 = handle2_.GetCenter().GetY(); | |
1738 | |
1739 // Put the label to the right of the right-most handle | |
1740 if (x1 < x2) | |
1741 { | |
1742 content.SetPosition(x2, y2); | |
1743 } | |
1744 else | |
1745 { | |
1746 content.SetPosition(x1, y1); | |
1747 } | |
1748 | |
1749 content.SetAnchor(BitmapAnchor_CenterLeft); | |
1750 content.SetBorder(10); | |
1751 | |
1752 double dx = x1 - x2; | |
1753 double dy = y1 - y2; | |
1754 double diameter = sqrt(dx * dx + dy * dy); // in millimeters | |
1755 | |
1756 double area = PI * diameter * diameter / 4.0; | |
1757 | |
1758 char buf[32]; | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1759 |
2000 | 1760 switch (units_) |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1761 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1762 case Units_Millimeters: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1763 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
|
1764 diameter / 10.0, |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1765 area / 100.0, |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1766 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
|
1767 break; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1768 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1769 case Units_Pixels: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1770 // 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
|
1771 sprintf(buf, "%0.1f px", diameter); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1772 break; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1773 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1774 default: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1775 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1776 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1777 |
1804 | 1778 content.SetText(buf); |
1779 | |
1780 label_.SetContent(content); | |
1781 } | |
1782 | |
1783 public: | |
1784 CircleAnnotation(AnnotationsSceneLayer& that, | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1785 Units units, |
1804 | 1786 const ScenePoint2D& p1, |
1787 const ScenePoint2D& p2) : | |
2000 | 1788 Annotation(that), |
1789 units_(units), | |
1980
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
1790 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p1))), |
0aac8f552d89
added pixel probe to the Stone Web viewer toolbar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1979
diff
changeset
|
1791 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p2))), |
1804 | 1792 segment_(AddTypedPrimitive<Segment>(new Segment(*this, p1, p2))), |
1793 circle_(AddTypedPrimitive<Circle>(new Circle(*this, p1, p2))), | |
1794 label_(AddTypedPrimitive<Text>(new Text(that, *this))) | |
1795 { | |
1819
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
1796 label_.SetColor(COLOR_TEXT); |
1804 | 1797 UpdateLabel(); |
1798 } | |
1799 | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1800 virtual unsigned int GetHandlesCount() const ORTHANC_OVERRIDE |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1801 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1802 return 2; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1803 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1804 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1805 virtual Handle& GetHandle(unsigned int index) const ORTHANC_OVERRIDE |
1804 | 1806 { |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1807 switch (index) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1808 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1809 case 0: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1810 return handle1_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1811 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1812 case 1: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1813 return handle2_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1814 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1815 default: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1816 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1817 } |
1804 | 1818 } |
1819 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1820 virtual void SignalMove(GeometricPrimitive& primitive, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
1821 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 1822 { |
1823 if (&primitive == &handle1_ || | |
1824 &primitive == &handle2_) | |
1825 { | |
1826 segment_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter()); | |
1827 circle_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter()); | |
1828 } | |
1829 else if (&primitive == &segment_) | |
1830 { | |
1831 handle1_.SetCenter(segment_.GetPosition1()); | |
1832 handle2_.SetCenter(segment_.GetPosition2()); | |
1833 circle_.SetPosition(segment_.GetPosition1(), segment_.GetPosition2()); | |
1834 } | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
1835 else if (&primitive == &circle_) |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
1836 { |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
1837 handle1_.SetCenter(circle_.GetPosition1()); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
1838 handle2_.SetCenter(circle_.GetPosition2()); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
1839 segment_.SetPosition(circle_.GetPosition1(), circle_.GetPosition2()); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
1840 } |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1841 else |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1842 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1843 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1844 } |
1804 | 1845 |
1846 UpdateLabel(); | |
1847 } | |
1848 | |
1976
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1849 virtual void UpdateProbe(const Scene2D& scene) ORTHANC_OVERRIDE |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1850 { |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1851 } |
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
1852 |
1804 | 1853 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE |
1854 { | |
1855 target = Json::objectValue; | |
1856 target[KEY_TYPE] = VALUE_CIRCLE; | |
1857 target[KEY_X1] = handle1_.GetCenter().GetX(); | |
1858 target[KEY_Y1] = handle1_.GetCenter().GetY(); | |
1859 target[KEY_X2] = handle2_.GetCenter().GetX(); | |
1860 target[KEY_Y2] = handle2_.GetCenter().GetY(); | |
1861 } | |
1862 | |
1863 static void Unserialize(AnnotationsSceneLayer& target, | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1864 Units units, |
1804 | 1865 const Json::Value& source) |
1866 { | |
1867 if (source.isMember(KEY_X1) && | |
1868 source.isMember(KEY_Y1) && | |
1869 source.isMember(KEY_X2) && | |
1870 source.isMember(KEY_Y2) && | |
1871 source[KEY_X1].isNumeric() && | |
1872 source[KEY_Y1].isNumeric() && | |
1873 source[KEY_X2].isNumeric() && | |
1874 source[KEY_Y2].isNumeric()) | |
1875 { | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1876 new CircleAnnotation(target, units, |
1804 | 1877 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), |
1878 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble())); | |
1879 } | |
1880 else | |
1881 { | |
1882 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an circle annotation"); | |
1883 } | |
1884 } | |
1885 }; | |
1886 | |
1887 | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1888 class AnnotationsSceneLayer::RectangleProbeAnnotation : public ProbingAnnotation |
1804 | 1889 { |
1890 private: | |
2000 | 1891 Units units_; |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1892 Handle& handle1_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1893 Handle& handle2_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1894 Segment& segment1_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1895 Segment& segment2_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1896 Segment& segment3_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1897 Segment& segment4_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1898 Text& label_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1899 |
1984
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1900 protected: |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1901 virtual void UpdateProbeForLayer(const ISceneLayer& layer) ORTHANC_OVERRIDE |
1804 | 1902 { |
1984
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1903 double x1 = handle1_.GetCenter().GetX(); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1904 double y1 = handle1_.GetCenter().GetY(); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1905 double x2 = handle2_.GetCenter().GetX(); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1906 double y2 = handle2_.GetCenter().GetY(); |
1990 | 1907 |
1804 | 1908 { |
1990 | 1909 // Put the label to the right of the right-most handle |
1910 //const double y = std::min(y1, y2); | |
1911 const double y = (y1 + y2) / 2.0; | |
1912 if (x1 < x2) | |
1913 { | |
1914 label_.SetPosition(x2, y); | |
1915 } | |
1916 else | |
1917 { | |
1918 label_.SetPosition(x1, y); | |
1919 } | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1920 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1921 |
1984
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1922 std::string text; |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1923 |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1924 char buf[32]; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1925 |
2000 | 1926 if (units_ == Units_Millimeters) |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1927 { |
1984
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1928 const double area = std::abs(x1 - x2) * std::abs(y1 - y2); |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1929 |
1987
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1930 sprintf(buf, "Area: %0.2f cm%c%c", |
1984
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1931 area / 100.0, |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1932 0xc2, 0xb2 /* two bytes corresponding to two power in UTF-8 */); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1933 text = buf; |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1934 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1935 |
1984
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1936 if (layer.GetType() == ISceneLayer::Type_FloatTexture) |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1937 { |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1938 const TextureBaseSceneLayer& texture = dynamic_cast<const TextureBaseSceneLayer&>(layer); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1939 const AffineTransform2D sceneToTexture = AffineTransform2D::Invert(texture.GetTransform()); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1940 |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1941 const Orthanc::ImageAccessor& image = texture.GetTexture(); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1942 assert(image.GetFormat() == Orthanc::PixelFormat_Float32); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1943 |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1944 sceneToTexture.Apply(x1, y1); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1945 sceneToTexture.Apply(x2, y2); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1946 int ix1 = static_cast<int>(std::floor(x1)); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1947 int iy1 = static_cast<int>(std::floor(y1)); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1948 int ix2 = static_cast<int>(std::floor(x2)); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1949 int iy2 = static_cast<int>(std::floor(y2)); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1950 |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1951 if (ix1 > ix2) |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1952 { |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1953 std::swap(ix1, ix2); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1954 } |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1955 |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1956 if (iy1 > iy2) |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1957 { |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1958 std::swap(iy1, iy2); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1959 } |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1960 |
1984
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1961 LinearAlgebra::OnlineVarianceEstimator estimator; |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1962 |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1963 for (int y = std::max(0, iy1); y <= std::min(static_cast<int>(image.GetHeight()) - 1, iy2); y++) |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1964 { |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1965 int x = std::max(0, ix1); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1966 |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1967 const float* p = reinterpret_cast<const float*>(image.GetConstRow(y)) + x; |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1968 |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1969 for (; x <= std::min(static_cast<int>(image.GetWidth()) - 1, ix2); x++, p++) |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1970 { |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1971 estimator.AddSample(*p); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1972 } |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1973 } |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1974 |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1975 if (estimator.GetCount() > 0) |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1976 { |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1977 if (!text.empty()) |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1978 { |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1979 text += "\n"; |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1980 } |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1981 sprintf(buf, "Mean: %0.1f\nStdDev: %0.1f", estimator.GetMean(), estimator.GetStandardDeviation()); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1982 text += buf; |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1983 } |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1984 } |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1985 |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
1986 label_.SetText(text); |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1987 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1988 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1989 public: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1990 RectangleProbeAnnotation(AnnotationsSceneLayer& that, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1991 Units units, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1992 const ScenePoint2D& p1, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1993 const ScenePoint2D& p2) : |
2000 | 1994 ProbingAnnotation(that), |
1995 units_(units), | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1996 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p1))), |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1997 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p2))), |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1998 segment1_(AddTypedPrimitive<Segment>(new Segment(*this, p1.GetX(), p1.GetY(), p2.GetX(), p1.GetY()))), |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
1999 segment2_(AddTypedPrimitive<Segment>(new Segment(*this, p2.GetX(), p1.GetY(), p2.GetX(), p2.GetY()))), |
1986 | 2000 segment3_(AddTypedPrimitive<Segment>(new Segment(*this, p1.GetX(), p2.GetY(), p2.GetX(), p2.GetY()))), |
2001 segment4_(AddTypedPrimitive<Segment>(new Segment(*this, p1.GetX(), p1.GetY(), p1.GetX(), p2.GetY()))), | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2002 label_(AddTypedPrimitive<Text>(new Text(that, *this))) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2003 { |
1984
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
2004 TextSceneLayer content; |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
2005 content.SetAnchor(BitmapAnchor_CenterLeft); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
2006 content.SetBorder(10); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
2007 content.SetText("?"); |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
2008 |
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
2009 label_.SetContent(content); |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2010 label_.SetColor(COLOR_TEXT); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2011 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2012 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2013 virtual unsigned int GetHandlesCount() const ORTHANC_OVERRIDE |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2014 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2015 return 2; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2016 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2017 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2018 virtual Handle& GetHandle(unsigned int index) const ORTHANC_OVERRIDE |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2019 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2020 switch (index) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2021 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2022 case 0: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2023 return handle1_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2024 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2025 case 1: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2026 return handle2_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2027 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2028 default: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2029 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2030 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2031 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2032 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2033 virtual void SignalMove(GeometricPrimitive& primitive, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2034 const Scene2D& scene) ORTHANC_OVERRIDE |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2035 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2036 if (&primitive == &handle1_ || |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2037 &primitive == &handle2_) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2038 { |
1986 | 2039 double x1 = handle1_.GetCenter().GetX(); |
2040 double y1 = handle1_.GetCenter().GetY(); | |
2041 double x2 = handle2_.GetCenter().GetX(); | |
2042 double y2 = handle2_.GetCenter().GetY(); | |
2043 | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2044 segment1_.SetPosition(x1, y1, x2, y1); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2045 segment2_.SetPosition(x2, y1, x2, y2); |
1986 | 2046 segment3_.SetPosition(x1, y2, x2, y2); |
2047 segment4_.SetPosition(x1, y1, x1, y2); | |
1804 | 2048 } |
1986 | 2049 else if (&primitive == &segment1_ || |
2050 &primitive == &segment2_ || | |
2051 &primitive == &segment3_ || | |
2052 &primitive == &segment4_) | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2053 { |
1986 | 2054 const Segment& segment = dynamic_cast<const Segment&>(primitive); |
2055 double x1 = segment.GetPosition1().GetX(); | |
2056 double y1 = segment.GetPosition1().GetY(); | |
2057 double x2 = segment.GetPosition2().GetX(); | |
2058 double y2 = segment.GetPosition2().GetY(); | |
1985
bb307007f8e2
improved interaction with rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1984
diff
changeset
|
2059 |
1986 | 2060 if (&primitive == &segment1_) |
2061 { | |
2062 y2 = y1 + handle2_.GetCenter().GetY() - handle1_.GetCenter().GetY(); | |
2063 } | |
2064 else if (&primitive == &segment2_) | |
2065 { | |
2066 x1 = x2 + handle1_.GetCenter().GetX() - handle2_.GetCenter().GetX(); | |
2067 } | |
2068 else if (&primitive == &segment3_) | |
2069 { | |
2070 y1 = y2 + handle1_.GetCenter().GetY() - handle2_.GetCenter().GetY(); | |
2071 } | |
2072 else if (&primitive == &segment4_) | |
2073 { | |
2074 x2 = x1 + handle2_.GetCenter().GetX() - handle1_.GetCenter().GetX(); | |
2075 } | |
2076 else | |
2077 { | |
2078 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
2079 } | |
1985
bb307007f8e2
improved interaction with rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1984
diff
changeset
|
2080 |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2081 handle1_.SetCenter(x1, y1); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2082 handle2_.SetCenter(x2, y2); |
1985
bb307007f8e2
improved interaction with rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1984
diff
changeset
|
2083 |
1986 | 2084 if (&primitive != &segment1_) |
2085 { | |
2086 segment1_.SetPosition(x1, y1, x2, y1); | |
2087 } | |
2088 | |
2089 if (&primitive != &segment2_) | |
2090 { | |
2091 segment2_.SetPosition(x2, y1, x2, y2); | |
2092 } | |
1985
bb307007f8e2
improved interaction with rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1984
diff
changeset
|
2093 |
1986 | 2094 if (&primitive != &segment3_) |
2095 { | |
2096 segment3_.SetPosition(x1, y2, x2, y2); | |
2097 } | |
1985
bb307007f8e2
improved interaction with rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1984
diff
changeset
|
2098 |
1986 | 2099 if (&primitive != &segment4_) |
2100 { | |
2101 segment4_.SetPosition(x1, y1, x1, y2); | |
2102 } | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2103 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2104 else |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2105 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2106 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2107 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2108 |
1984
187a261d7ae2
computation of mean and stddev in rectangle probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1983
diff
changeset
|
2109 TagProbeAsChanged(); |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2110 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2111 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2112 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2113 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2114 target = Json::objectValue; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2115 target[KEY_TYPE] = VALUE_RECTANGLE_PROBE; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2116 target[KEY_X1] = handle1_.GetCenter().GetX(); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2117 target[KEY_Y1] = handle1_.GetCenter().GetY(); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2118 target[KEY_X2] = handle2_.GetCenter().GetX(); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2119 target[KEY_Y2] = handle2_.GetCenter().GetY(); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2120 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2121 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2122 static void Unserialize(AnnotationsSceneLayer& target, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2123 Units units, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2124 const Json::Value& source) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2125 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2126 if (source.isMember(KEY_X1) && |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2127 source.isMember(KEY_Y1) && |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2128 source.isMember(KEY_X2) && |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2129 source.isMember(KEY_Y2) && |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2130 source[KEY_X1].isNumeric() && |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2131 source[KEY_Y1].isNumeric() && |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2132 source[KEY_X2].isNumeric() && |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2133 source[KEY_Y2].isNumeric()) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2134 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2135 new RectangleProbeAnnotation(target, units, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2136 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2137 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble())); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2138 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2139 else |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2140 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2141 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize a rectangle probe annotation"); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2142 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2143 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2144 }; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2145 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2146 |
1987
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2147 class AnnotationsSceneLayer::EllipseProbeAnnotation : public ProbingAnnotation |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2148 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2149 private: |
2000 | 2150 Units units_; |
1987
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2151 Handle& handle1_; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2152 Handle& handle2_; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2153 Ellipse& ellipse_; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2154 Text& label_; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2155 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2156 protected: |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2157 virtual void UpdateProbeForLayer(const ISceneLayer& layer) ORTHANC_OVERRIDE |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2158 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2159 double x1 = handle1_.GetCenter().GetX(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2160 double y1 = handle1_.GetCenter().GetY(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2161 double x2 = handle2_.GetCenter().GetX(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2162 double y2 = handle2_.GetCenter().GetY(); |
1990 | 2163 |
1987
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2164 { |
1990 | 2165 // Put the label to the right of the right-most handle |
2166 //const double y = std::min(y1, y2); | |
2167 const double y = (y1 + y2) / 2.0; | |
2168 if (x1 < x2) | |
2169 { | |
2170 label_.SetPosition(x2, y); | |
2171 } | |
2172 else | |
2173 { | |
2174 label_.SetPosition(x1, y); | |
2175 } | |
1987
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2176 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2177 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2178 std::string text; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2179 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2180 char buf[32]; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2181 |
2000 | 2182 if (units_ == Units_Millimeters) |
1987
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2183 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2184 sprintf(buf, "Area: %0.2f cm%c%c", |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2185 ellipse_.GetArea() / 100.0, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2186 0xc2, 0xb2 /* two bytes corresponding to two power in UTF-8 */); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2187 text = buf; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2188 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2189 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2190 if (layer.GetType() == ISceneLayer::Type_FloatTexture) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2191 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2192 const TextureBaseSceneLayer& texture = dynamic_cast<const TextureBaseSceneLayer&>(layer); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2193 const AffineTransform2D& textureToScene = texture.GetTransform(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2194 const AffineTransform2D sceneToTexture = AffineTransform2D::Invert(textureToScene); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2195 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2196 const Orthanc::ImageAccessor& image = texture.GetTexture(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2197 assert(image.GetFormat() == Orthanc::PixelFormat_Float32); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2198 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2199 sceneToTexture.Apply(x1, y1); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2200 sceneToTexture.Apply(x2, y2); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2201 int ix1 = static_cast<int>(std::floor(x1)); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2202 int iy1 = static_cast<int>(std::floor(y1)); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2203 int ix2 = static_cast<int>(std::floor(x2)); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2204 int iy2 = static_cast<int>(std::floor(y2)); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2205 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2206 if (ix1 > ix2) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2207 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2208 std::swap(ix1, ix2); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2209 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2210 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2211 if (iy1 > iy2) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2212 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2213 std::swap(iy1, iy2); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2214 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2215 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2216 LinearAlgebra::OnlineVarianceEstimator estimator; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2217 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2218 for (int y = std::max(0, iy1); y <= std::min(static_cast<int>(image.GetHeight()) - 1, iy2); y++) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2219 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2220 int x = std::max(0, ix1); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2221 const float* p = reinterpret_cast<const float*>(image.GetConstRow(y)) + x; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2222 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2223 for (; x <= std::min(static_cast<int>(image.GetWidth()) - 1, ix2); x++, p++) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2224 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2225 double yy = static_cast<double>(y) + 0.5; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2226 double xx = static_cast<double>(x) + 0.5; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2227 textureToScene.Apply(xx, yy); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2228 if (ellipse_.IsPointInside(ScenePoint2D(xx, yy))) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2229 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2230 estimator.AddSample(*p); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2231 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2232 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2233 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2234 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2235 if (estimator.GetCount() > 0) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2236 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2237 if (!text.empty()) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2238 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2239 text += "\n"; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2240 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2241 sprintf(buf, "Mean: %0.1f\nStdDev: %0.1f", estimator.GetMean(), estimator.GetStandardDeviation()); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2242 text += buf; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2243 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2244 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2245 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2246 label_.SetText(text); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2247 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2248 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2249 public: |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2250 EllipseProbeAnnotation(AnnotationsSceneLayer& that, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2251 Units units, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2252 const ScenePoint2D& p1, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2253 const ScenePoint2D& p2) : |
2000 | 2254 ProbingAnnotation(that), |
2255 units_(units), | |
1987
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2256 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p1))), |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2257 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, Handle::Shape_Square, p2))), |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2258 ellipse_(AddTypedPrimitive<Ellipse>(new Ellipse(*this, p1, p2))), |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2259 label_(AddTypedPrimitive<Text>(new Text(that, *this))) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2260 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2261 TextSceneLayer content; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2262 content.SetAnchor(BitmapAnchor_CenterLeft); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2263 content.SetBorder(10); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2264 content.SetText("?"); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2265 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2266 label_.SetContent(content); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2267 label_.SetColor(COLOR_TEXT); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2268 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2269 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2270 virtual unsigned int GetHandlesCount() const ORTHANC_OVERRIDE |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2271 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2272 return 2; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2273 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2274 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2275 virtual Handle& GetHandle(unsigned int index) const ORTHANC_OVERRIDE |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2276 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2277 switch (index) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2278 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2279 case 0: |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2280 return handle1_; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2281 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2282 case 1: |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2283 return handle2_; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2284 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2285 default: |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2286 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2287 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2288 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2289 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2290 virtual void SignalMove(GeometricPrimitive& primitive, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2291 const Scene2D& scene) ORTHANC_OVERRIDE |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2292 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2293 if (&primitive == &handle1_ || |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2294 &primitive == &handle2_) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2295 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2296 ellipse_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter()); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2297 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2298 else if (&primitive == &ellipse_) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2299 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2300 handle1_.SetCenter(ellipse_.GetPosition1()); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2301 handle2_.SetCenter(ellipse_.GetPosition2()); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2302 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2303 else |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2304 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2305 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2306 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2307 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2308 TagProbeAsChanged(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2309 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2310 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2311 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2312 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2313 target = Json::objectValue; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2314 target[KEY_TYPE] = VALUE_ELLIPSE_PROBE; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2315 target[KEY_X1] = handle1_.GetCenter().GetX(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2316 target[KEY_Y1] = handle1_.GetCenter().GetY(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2317 target[KEY_X2] = handle2_.GetCenter().GetX(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2318 target[KEY_Y2] = handle2_.GetCenter().GetY(); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2319 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2320 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2321 static void Unserialize(AnnotationsSceneLayer& target, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2322 Units units, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2323 const Json::Value& source) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2324 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2325 if (source.isMember(KEY_X1) && |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2326 source.isMember(KEY_Y1) && |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2327 source.isMember(KEY_X2) && |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2328 source.isMember(KEY_Y2) && |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2329 source[KEY_X1].isNumeric() && |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2330 source[KEY_Y1].isNumeric() && |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2331 source[KEY_X2].isNumeric() && |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2332 source[KEY_Y2].isNumeric()) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2333 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2334 new EllipseProbeAnnotation(target, units, |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2335 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2336 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble())); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2337 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2338 else |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2339 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2340 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an ellipse probe annotation"); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2341 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2342 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2343 }; |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2344 |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2345 |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2346 class AnnotationsSceneLayer::CreateTwoHandlesTracker : public IFlexiblePointerTracker |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2347 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2348 private: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2349 AnnotationsSceneLayer& layer_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2350 Annotation* annotation_; |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2351 AffineTransform2D canvasToScene_; |
2001
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2352 |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2353 protected: |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2354 AnnotationsSceneLayer& GetLayer() const |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2355 { |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2356 return layer_; |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2357 } |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2358 |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2359 const Annotation& GetAnnotation() const |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2360 { |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2361 if (IsAlive()) |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2362 { |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2363 assert(annotation_ != NULL); |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2364 return *annotation_; |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2365 } |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2366 else |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2367 { |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2368 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2369 } |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2370 } |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2371 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2372 public: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2373 CreateTwoHandlesTracker(Annotation& annotation, |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2374 const AffineTransform2D& canvasToScene) : |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2375 layer_(annotation.GetParentLayer()), |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2376 annotation_(&annotation), |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2377 canvasToScene_(canvasToScene) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2378 { |
1804 | 2379 assert(annotation_ != NULL && |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2380 annotation_->GetHandlesCount() >= 2); |
1804 | 2381 } |
2382 | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2383 virtual void PointerMove(const PointerEvent& event, |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2384 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 2385 { |
2386 if (annotation_ != NULL) | |
2387 { | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2388 annotation_->GetHandle(1).SetCenter(event.GetMainPosition().Apply(canvasToScene_)); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2389 annotation_->SignalMove(annotation_->GetHandle(1), scene); |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
2390 |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2391 layer_.BroadcastMessage(AnnotationChangedMessage(layer_)); |
1804 | 2392 } |
2393 } | |
2394 | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2395 virtual void PointerUp(const PointerEvent& event, |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2396 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 2397 { |
2398 annotation_ = NULL; // IsAlive() becomes false | |
2399 | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2400 layer_.BroadcastMessage(AnnotationAddedMessage(layer_)); |
1804 | 2401 } |
2402 | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2403 virtual void PointerDown(const PointerEvent& event, |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2404 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 2405 { |
2406 } | |
2407 | |
2408 virtual bool IsAlive() const ORTHANC_OVERRIDE | |
2409 { | |
2410 return (annotation_ != NULL); | |
2411 } | |
2412 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2413 virtual void Cancel(const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 2414 { |
2415 if (annotation_ != NULL) | |
2416 { | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2417 layer_.DeleteAnnotation(annotation_); |
1804 | 2418 annotation_ = NULL; |
2419 } | |
2420 } | |
2421 }; | |
2422 | |
2423 | |
2424 class AnnotationsSceneLayer::CreateAngleTracker : public IFlexiblePointerTracker | |
2425 { | |
2426 private: | |
2427 AnnotationsSceneLayer& that_; | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2428 LengthAnnotation* length_; |
1804 | 2429 AngleAnnotation* angle_; |
2430 AffineTransform2D canvasToScene_; | |
2431 | |
2432 public: | |
2433 CreateAngleTracker(AnnotationsSceneLayer& that, | |
2434 const ScenePoint2D& sceneClick, | |
2435 const AffineTransform2D& canvasToScene) : | |
2436 that_(that), | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2437 length_(NULL), |
1804 | 2438 angle_(NULL), |
2439 canvasToScene_(canvasToScene) | |
2440 { | |
2000 | 2441 length_ = new LengthAnnotation(that, that.GetUnits(), false /* no length label */, sceneClick, sceneClick); |
1804 | 2442 } |
2443 | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2444 virtual void PointerMove(const PointerEvent& event, |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2445 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 2446 { |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2447 if (length_ != NULL) |
1804 | 2448 { |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2449 length_->GetHandle(1).SetCenter(event.GetMainPosition().Apply(canvasToScene_)); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2450 length_->SignalMove(length_->GetHandle(1), scene); |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
2451 that_.BroadcastMessage(AnnotationChangedMessage(that_)); |
1804 | 2452 } |
2453 | |
2454 if (angle_ != NULL) | |
2455 { | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2456 angle_->GetHandle(2).SetCenter(event.GetMainPosition().Apply(canvasToScene_)); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2457 angle_->SignalMove(angle_->GetHandle(2), scene); |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
2458 that_.BroadcastMessage(AnnotationChangedMessage(that_)); |
1804 | 2459 } |
2460 } | |
2461 | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2462 virtual void PointerUp(const PointerEvent& event, |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2463 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 2464 { |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2465 if (length_ != NULL) |
1804 | 2466 { |
2467 // End of first step: The first segment is available, now create the angle | |
2468 | |
2000 | 2469 angle_ = new AngleAnnotation(that_, length_->GetHandle(0).GetCenter(), |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2470 length_->GetHandle(1).GetCenter(), |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2471 length_->GetHandle(1).GetCenter()); |
1804 | 2472 |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2473 that_.DeleteAnnotation(length_); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2474 length_ = NULL; |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
2475 |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
2476 that_.BroadcastMessage(AnnotationChangedMessage(that_)); |
1804 | 2477 } |
2478 else | |
2479 { | |
2480 angle_ = NULL; // IsAlive() becomes false | |
2481 | |
2482 that_.BroadcastMessage(AnnotationAddedMessage(that_)); | |
2483 } | |
2484 } | |
2485 | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2486 virtual void PointerDown(const PointerEvent& event, |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2487 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 2488 { |
2489 } | |
2490 | |
2491 virtual bool IsAlive() const ORTHANC_OVERRIDE | |
2492 { | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2493 return (length_ != NULL || |
1804 | 2494 angle_ != NULL); |
2495 } | |
2496 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2497 virtual void Cancel(const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 2498 { |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2499 if (length_ != NULL) |
1804 | 2500 { |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2501 that_.DeleteAnnotation(length_); |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2502 length_ = NULL; |
1804 | 2503 } |
2504 | |
2505 if (angle_ != NULL) | |
2506 { | |
2507 that_.DeleteAnnotation(angle_); | |
2508 angle_ = NULL; | |
2509 } | |
2510 } | |
2511 }; | |
2512 | |
2513 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2514 class AnnotationsSceneLayer::CreatePixelProbeTracker : public IFlexiblePointerTracker |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2515 { |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2516 public: |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2517 CreatePixelProbeTracker(AnnotationsSceneLayer& that, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2518 const ScenePoint2D& sceneClick, |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2519 const Scene2D& scene) |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2520 { |
2000 | 2521 PixelProbeAnnotation* annotation = new PixelProbeAnnotation(that, sceneClick); |
1976
d71acf30970a
fixed serialization of pixel probes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
2522 annotation->UpdateProbe(scene); |
1978
95449b0e064a
pixel probe is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1977
diff
changeset
|
2523 that.BroadcastMessage(AnnotationAddedMessage(that)); |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2524 } |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2525 |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2526 virtual void PointerMove(const PointerEvent& event, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2527 const Scene2D& scene) ORTHANC_OVERRIDE |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2528 { |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2529 } |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2530 |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2531 virtual void PointerUp(const PointerEvent& event, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2532 const Scene2D& scene) ORTHANC_OVERRIDE |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2533 { |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2534 } |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2535 |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2536 virtual void PointerDown(const PointerEvent& event, |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2537 const Scene2D& scene) ORTHANC_OVERRIDE |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2538 { |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2539 } |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2540 |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2541 virtual bool IsAlive() const ORTHANC_OVERRIDE |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2542 { |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2543 return false; |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2544 } |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2545 |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2546 virtual void Cancel(const Scene2D& scene) ORTHANC_OVERRIDE |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2547 { |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2548 } |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2549 }; |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2550 |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2551 |
2001
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2552 class AnnotationsSceneLayer::CreateTextAnnotationTracker : public CreateTwoHandlesTracker |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2553 { |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2554 public: |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2555 CreateTextAnnotationTracker(AnnotationsSceneLayer& that, |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2556 const std::string& label, |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2557 const ScenePoint2D& position, |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2558 const AffineTransform2D& canvasToScene) : |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2559 CreateTwoHandlesTracker(*new TextAnnotation(that, label, position, position), canvasToScene) |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2560 { |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2561 } |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2562 |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2563 virtual void PointerUp(const PointerEvent& event, |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2564 const Scene2D& scene) ORTHANC_OVERRIDE |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2565 { |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2566 std::unique_ptr<TextAnnotationRequiredMessage> request; |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2567 |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2568 { |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2569 const TextAnnotation& annotation = dynamic_cast<const TextAnnotation&>(GetAnnotation()); |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2570 request.reset(new TextAnnotationRequiredMessage(GetLayer(), annotation.GetPointedPosition(), annotation.GetLabelPosition())); |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2571 } |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2572 |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2573 Cancel(scene); // Warning: "annotation_" is now invalid! |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2574 |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2575 GetLayer().BroadcastMessage(AnnotationChangedMessage(GetLayer())); |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2576 GetLayer().BroadcastMessage(*request); |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2577 } |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2578 }; |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2579 |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2580 |
1804 | 2581 // Dummy tracker that is only used for deletion, in order to warn |
2582 // 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
|
2583 class AnnotationsSceneLayer::RemoveTracker : public IFlexiblePointerTracker |
1804 | 2584 { |
2585 public: | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
2586 RemoveTracker() |
1804 | 2587 { |
2588 } | |
2589 | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2590 virtual void PointerMove(const PointerEvent& event, |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2591 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 2592 { |
2593 } | |
2594 | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2595 virtual void PointerUp(const PointerEvent& event, |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2596 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 2597 { |
2598 } | |
2599 | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2600 virtual void PointerDown(const PointerEvent& event, |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2601 const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 2602 { |
2603 } | |
2604 | |
2605 virtual bool IsAlive() const ORTHANC_OVERRIDE | |
2606 { | |
2607 return false; | |
2608 } | |
2609 | |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2610 virtual void Cancel(const Scene2D& scene) ORTHANC_OVERRIDE |
1804 | 2611 { |
2612 } | |
2613 }; | |
2614 | |
2615 | |
2616 void AnnotationsSceneLayer::AddAnnotation(Annotation* annotation) | |
2617 { | |
2618 assert(annotation != NULL); | |
2619 assert(annotations_.find(annotation) == annotations_.end()); | |
2620 annotations_.insert(annotation); | |
2621 } | |
2622 | |
2623 | |
2624 void AnnotationsSceneLayer::DeleteAnnotation(Annotation* annotation) | |
2625 { | |
2626 if (annotation != NULL) | |
2627 { | |
2628 assert(annotations_.find(annotation) != annotations_.end()); | |
2629 annotations_.erase(annotation); | |
2630 delete annotation; | |
2631 } | |
2632 } | |
2633 | |
2634 | |
2635 void AnnotationsSceneLayer::DeletePrimitive(GeometricPrimitive* primitive) | |
2636 { | |
2637 if (primitive != NULL) | |
2638 { | |
2639 assert(primitives_.find(primitive) != primitives_.end()); | |
2640 primitives_.erase(primitive); | |
2641 delete primitive; | |
2642 } | |
2643 } | |
2644 | |
2645 | |
2646 void AnnotationsSceneLayer::TagSubLayerToRemove(size_t subLayerIndex) | |
2647 { | |
2648 assert(subLayersToRemove_.find(subLayerIndex) == subLayersToRemove_.end()); | |
2649 subLayersToRemove_.insert(subLayerIndex); | |
2650 } | |
2651 | |
2652 | |
2653 AnnotationsSceneLayer::AnnotationsSceneLayer(size_t macroLayerIndex) : | |
2654 activeTool_(Tool_Edit), | |
2655 macroLayerIndex_(macroLayerIndex), | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2656 polylineSubLayer_(0), // dummy initialization |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2657 units_(Units_Pixels), |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2658 probedLayer_(0) |
1804 | 2659 { |
2660 } | |
2661 | |
2662 | |
2663 void AnnotationsSceneLayer::Clear() | |
2664 { | |
2665 for (Annotations::iterator it = annotations_.begin(); it != annotations_.end(); ++it) | |
2666 { | |
2667 assert(*it != NULL); | |
2668 delete *it; | |
2669 } | |
2670 | |
2671 annotations_.clear(); | |
1812
db341679dc9f
ViewerViewport::StoneAnnotationsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1809
diff
changeset
|
2672 |
db341679dc9f
ViewerViewport::StoneAnnotationsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1809
diff
changeset
|
2673 ClearHover(); |
1804 | 2674 } |
2675 | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2676 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2677 void AnnotationsSceneLayer::SetUnits(Units units) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2678 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2679 if (units_ != units) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2680 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2681 Clear(); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2682 units_ = units; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2683 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2684 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2685 |
1804 | 2686 |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2687 void AnnotationsSceneLayer::AddLengthAnnotation(const ScenePoint2D& p1, |
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2688 const ScenePoint2D& p2) |
1806
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2689 { |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2690 annotations_.insert(new LengthAnnotation(*this, units_, true /* show label */, p1, p2)); |
2001
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2691 BroadcastMessage(AnnotationChangedMessage(*this)); |
1806
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2692 } |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2693 |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2694 |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2695 void AnnotationsSceneLayer::AddCircleAnnotation(const ScenePoint2D& p1, |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2696 const ScenePoint2D& p2) |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2697 { |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2698 annotations_.insert(new CircleAnnotation(*this, units_, p1, p2)); |
2001
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2699 BroadcastMessage(AnnotationChangedMessage(*this)); |
1806
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2700 } |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2701 |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2702 |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2703 void AnnotationsSceneLayer::AddAngleAnnotation(const ScenePoint2D& p1, |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2704 const ScenePoint2D& p2, |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2705 const ScenePoint2D& p3) |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2706 { |
2000 | 2707 annotations_.insert(new AngleAnnotation(*this, p1, p2, p3)); |
2001
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2708 BroadcastMessage(AnnotationChangedMessage(*this)); |
1806
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2709 } |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2710 |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
2711 |
1804 | 2712 void AnnotationsSceneLayer::Render(Scene2D& scene) |
2713 { | |
1977 | 2714 // First, update the probes |
2715 for (Annotations::const_iterator it = annotations_.begin(); it != annotations_.end(); ++it) | |
2716 { | |
2717 assert(*it != NULL); | |
2718 (*it)->UpdateProbe(scene); | |
2719 } | |
2720 | |
1804 | 2721 MacroSceneLayer* macro = NULL; |
2722 | |
2723 if (scene.HasLayer(macroLayerIndex_)) | |
2724 { | |
2725 macro = &dynamic_cast<MacroSceneLayer&>(scene.GetLayer(macroLayerIndex_)); | |
2726 } | |
2727 else | |
2728 { | |
2729 macro = &dynamic_cast<MacroSceneLayer&>(scene.SetLayer(macroLayerIndex_, new MacroSceneLayer)); | |
2730 polylineSubLayer_ = macro->AddLayer(new PolylineSceneLayer); | |
2731 } | |
2732 | |
2733 for (SubLayers::const_iterator it = subLayersToRemove_.begin(); it != subLayersToRemove_.end(); ++it) | |
2734 { | |
2735 assert(macro->HasLayer(*it)); | |
2736 macro->DeleteLayer(*it); | |
2737 } | |
2738 | |
2739 subLayersToRemove_.clear(); | |
2740 | |
2741 std::unique_ptr<PolylineSceneLayer> polyline(new PolylineSceneLayer); | |
2742 | |
2743 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | |
2744 { | |
2745 assert(*it != NULL); | |
2746 GeometricPrimitive& primitive = **it; | |
2747 | |
2748 primitive.RenderPolylineLayer(*polyline, scene); | |
2749 | |
2750 if (primitive.IsModified()) | |
2751 { | |
2752 primitive.RenderOtherLayers(*macro, scene); | |
2753 primitive.SetModified(false); | |
2754 } | |
2755 } | |
2756 | |
2757 macro->UpdateLayer(polylineSubLayer_, polyline.release()); | |
2758 } | |
2759 | |
2760 | |
2761 bool AnnotationsSceneLayer::ClearHover() | |
2762 { | |
2763 bool needsRefresh = false; | |
2764 | |
2765 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | |
2766 { | |
2767 assert(*it != NULL); | |
2768 if ((*it)->IsHover()) | |
2769 { | |
2770 (*it)->SetHover(false); | |
2771 needsRefresh = true; | |
2772 } | |
2773 } | |
2774 | |
2775 return needsRefresh; | |
2776 } | |
2777 | |
2778 | |
2779 bool AnnotationsSceneLayer::SetMouseHover(const ScenePoint2D& p, | |
2780 const Scene2D& scene) | |
2781 { | |
2782 if (activeTool_ == Tool_None) | |
2783 { | |
2784 return ClearHover(); | |
2785 } | |
2786 else | |
2787 { | |
2788 bool needsRefresh = false; | |
2789 | |
2790 const ScenePoint2D s = p.Apply(scene.GetCanvasToSceneTransform()); | |
2791 | |
2792 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | |
2793 { | |
2794 assert(*it != NULL); | |
2795 bool hover = (*it)->IsHit(s, scene); | |
2796 | |
2797 if ((*it)->IsHover() != hover) | |
2798 { | |
2799 needsRefresh = true; | |
2800 } | |
2801 | |
2802 (*it)->SetHover(hover); | |
2803 } | |
2804 | |
2805 return needsRefresh; | |
2806 } | |
2807 } | |
2808 | |
2809 | |
2810 IFlexiblePointerTracker* AnnotationsSceneLayer::CreateTracker(const ScenePoint2D& p, | |
2811 const Scene2D& scene) | |
2812 { | |
1972
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2813 /** |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2814 * WARNING: The created trackers must NOT keep a reference to "scene"! |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2815 **/ |
9c0adcc8feec
refactoring to simplify OneGesturePointerTracker
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
2816 |
1804 | 2817 if (activeTool_ == Tool_None) |
2818 { | |
2819 return NULL; | |
2820 } | |
2821 else | |
2822 { | |
2823 const ScenePoint2D s = p.Apply(scene.GetCanvasToSceneTransform()); | |
2824 | |
2825 GeometricPrimitive* bestHit = NULL; | |
2826 | |
2827 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | |
2828 { | |
2829 assert(*it != NULL); | |
2830 if ((*it)->IsHit(s, scene)) | |
2831 { | |
2832 if (bestHit == NULL || | |
2833 bestHit->GetDepth() > (*it)->GetDepth()) | |
2834 { | |
2835 bestHit = *it; | |
2836 } | |
2837 } | |
2838 } | |
2839 | |
2840 if (bestHit != NULL) | |
2841 { | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
2842 if (activeTool_ == Tool_Remove) |
1804 | 2843 { |
2844 DeleteAnnotation(&bestHit->GetParentAnnotation()); | |
2845 BroadcastMessage(AnnotationRemovedMessage(*this)); | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
2846 return new RemoveTracker; |
1804 | 2847 } |
2848 else | |
2849 { | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
2850 return new EditPrimitiveTracker(*this, *bestHit, s, scene.GetCanvasToSceneTransform()); |
1804 | 2851 } |
2852 } | |
2853 else | |
2854 { | |
2855 switch (activeTool_) | |
2856 { | |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2857 case Tool_Length: |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2858 { |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2859 Annotation* annotation = new LengthAnnotation(*this, units_, true /* show label */, s, s); |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2860 return new CreateTwoHandlesTracker(*annotation, scene.GetCanvasToSceneTransform()); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2861 } |
1804 | 2862 |
2863 case Tool_Circle: | |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2864 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2865 Annotation* annotation = new CircleAnnotation(*this, units_, s, s); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2866 return new CreateTwoHandlesTracker(*annotation, scene.GetCanvasToSceneTransform()); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2867 } |
1804 | 2868 |
2869 case Tool_Angle: | |
2000 | 2870 return new CreateAngleTracker(*this, s, scene.GetCanvasToSceneTransform()); |
1804 | 2871 |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2872 case Tool_PixelProbe: |
2000 | 2873 return new CreatePixelProbeTracker(*this, s, scene); |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2874 |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2875 case Tool_RectangleProbe: |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2876 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2877 Annotation* annotation = new RectangleProbeAnnotation(*this, units_, s, s); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2878 return new CreateTwoHandlesTracker(*annotation, scene.GetCanvasToSceneTransform()); |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2879 } |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2880 |
1987
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2881 case Tool_EllipseProbe: |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2882 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2883 Annotation* annotation = new EllipseProbeAnnotation(*this, units_, s, s); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2884 return new CreateTwoHandlesTracker(*annotation, scene.GetCanvasToSceneTransform()); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2885 } |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2886 |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
2887 case Tool_TextAnnotation: |
2001
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
2888 return new CreateTextAnnotationTracker(*this, "" /* empty label */, s, scene.GetCanvasToSceneTransform()); |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2889 |
1804 | 2890 default: |
2891 return NULL; | |
2892 } | |
2893 } | |
2894 } | |
2895 } | |
2896 | |
2897 | |
2898 void AnnotationsSceneLayer::Serialize(Json::Value& target) const | |
2899 { | |
2900 Json::Value annotations = Json::arrayValue; | |
2901 | |
2902 for (Annotations::const_iterator it = annotations_.begin(); it != annotations_.end(); ++it) | |
2903 { | |
2904 assert(*it != NULL); | |
2905 | |
2906 Json::Value item; | |
2907 (*it)->Serialize(item); | |
2908 annotations.append(item); | |
2909 } | |
2910 | |
2911 target = Json::objectValue; | |
2912 target[KEY_ANNOTATIONS] = annotations; | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2913 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2914 switch (units_) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2915 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2916 case Units_Millimeters: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2917 target[KEY_UNITS] = VALUE_MILLIMETERS; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2918 break; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2919 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2920 case Units_Pixels: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2921 target[KEY_UNITS] = VALUE_PIXELS; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2922 break; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2923 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2924 default: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2925 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2926 } |
1804 | 2927 } |
2928 | |
2929 | |
2930 void AnnotationsSceneLayer::Unserialize(const Json::Value& serialized) | |
2931 { | |
2932 Clear(); | |
2933 | |
2934 if (serialized.type() != Json::objectValue || | |
2935 !serialized.isMember(KEY_ANNOTATIONS) || | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2936 !serialized.isMember(KEY_UNITS) || |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2937 serialized[KEY_ANNOTATIONS].type() != Json::arrayValue || |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2938 serialized[KEY_UNITS].type() != Json::stringValue) |
1804 | 2939 { |
2940 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize a set of annotations"); | |
2941 } | |
2942 | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2943 const std::string& u = serialized[KEY_UNITS].asString(); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2944 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2945 if (u == VALUE_MILLIMETERS) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2946 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2947 units_ = Units_Millimeters; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2948 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2949 else if (u == VALUE_PIXELS) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2950 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2951 units_ = Units_Pixels; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2952 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2953 else |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2954 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2955 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
|
2956 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2957 |
1804 | 2958 const Json::Value& annotations = serialized[KEY_ANNOTATIONS]; |
2959 | |
2960 for (Json::Value::ArrayIndex i = 0; i < annotations.size(); i++) | |
2961 { | |
2962 if (annotations[i].type() != Json::objectValue || | |
2963 !annotations[i].isMember(KEY_TYPE) || | |
2964 annotations[i][KEY_TYPE].type() != Json::stringValue) | |
2965 { | |
2966 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
2967 } | |
2968 | |
2969 const std::string& type = annotations[i][KEY_TYPE].asString(); | |
2970 | |
2971 if (type == VALUE_ANGLE) | |
2972 { | |
2000 | 2973 AngleAnnotation::Unserialize(*this, annotations[i]); |
1804 | 2974 } |
2975 else if (type == VALUE_CIRCLE) | |
2976 { | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
2977 CircleAnnotation::Unserialize(*this, units_, annotations[i]); |
1804 | 2978 } |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2979 else if (type == VALUE_LENGTH) |
1804 | 2980 { |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2981 LengthAnnotation::Unserialize(*this, units_, annotations[i]); |
1804 | 2982 } |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2983 else if (type == VALUE_PIXEL_PROBE) |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2984 { |
2000 | 2985 PixelProbeAnnotation::Unserialize(*this, annotations[i]); |
1983
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2986 } |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2987 else if (type == VALUE_RECTANGLE_PROBE) |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2988 { |
20fa913272b7
drawing rectangle probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
2989 RectangleProbeAnnotation::Unserialize(*this, units_, annotations[i]); |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1972
diff
changeset
|
2990 } |
1987
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2991 else if (type == VALUE_ELLIPSE_PROBE) |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2992 { |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2993 EllipseProbeAnnotation::Unserialize(*this, units_, annotations[i]); |
a595776232bb
added ellipse probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
2994 } |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
2995 else if (type == VALUE_TEXT_ANNOTATION) |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1990
diff
changeset
|
2996 { |
2000 | 2997 TextAnnotation::Unserialize(*this, annotations[i]); |
1999
709b90ae0f89
starting text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
2998 } |
1804 | 2999 else |
3000 { | |
3001 LOG(ERROR) << "Cannot unserialize unknown type of annotation: " << type; | |
3002 } | |
3003 } | |
3004 } | |
2001
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
3005 |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
3006 |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
3007 void AnnotationsSceneLayer::AddTextAnnotation(const std::string& label, |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
3008 const ScenePoint2D& pointedPosition, |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
3009 const ScenePoint2D& labelPosition) |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
3010 { |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
3011 annotations_.insert(new TextAnnotation(*this, label, pointedPosition, labelPosition)); |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
3012 BroadcastMessage(AnnotationChangedMessage(*this)); |
e943a84da9ac
creation of text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2000
diff
changeset
|
3013 } |
1804 | 3014 } |