comparison Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewer.cpp @ 1805:de7cea710008

recovery of old SdlSimpleViewer sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 20 May 2021 17:05:30 +0200
parents 5a872e69c74f
children 0840a25c6d41
comparison
equal deleted inserted replaced
1804:5a872e69c74f 1805:de7cea710008
17 * You should have received a copy of the GNU Affero General Public License 17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/ 19 **/
20 20
21 21
22
23 #define SAMPLE_USE_OPENGL 1
24 #define SAMPLE_USE_ANNOTATIONS_LAYER 1
25
26
22 #include "SdlSimpleViewerApplication.h" 27 #include "SdlSimpleViewerApplication.h"
23 #include "../SdlHelpers.h" 28 #include "../SdlHelpers.h"
24 #include "../../Common/SampleHelpers.h" 29 #include "../../Common/SampleHelpers.h"
25 30
26 #include "../../../../OrthancStone/Sources/Loaders/GenericLoadersContext.h" 31 #include "../../../../OrthancStone/Sources/Loaders/GenericLoadersContext.h"
68 ; 73 ;
69 74
70 std::cout << desc << std::endl; 75 std::cout << desc << std::endl;
71 76
72 std::cout << std::endl << "Keyboard shorcuts:" << std::endl 77 std::cout << std::endl << "Keyboard shorcuts:" << std::endl
78 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
79 << " a\tCreate angle annotations" << std::endl
80 << " c\tCreate circle annotations" << std::endl
81 << " d\tDelete mode for annotations" << std::endl
82 << " e\tEdit mode, don't create annotation (default)" << std::endl
83 << " l\tCreate line annotations" << std::endl
84 #else
73 << " a\tEnable/disable the angle annotation tool" << std::endl 85 << " a\tEnable/disable the angle annotation tool" << std::endl
86 << " l\tEnable/disable the line annotation tool" << std::endl
87 << " r\tRedo the last edit to the annotation tools" << std::endl
88 << " u\tUndo the last edit to the annotation tools" << std::endl
89 #endif
74 << " f\tToggle fullscreen display" << std::endl 90 << " f\tToggle fullscreen display" << std::endl
75 << " l\tEnable/disable the line annotation tool" << std::endl
76 << " q\tExit" << std::endl 91 << " q\tExit" << std::endl
77 << " r\tRedo the last edit to the annotation tools" << std::endl
78 << " s\tFit the viewpoint to the image" << std::endl 92 << " s\tFit the viewpoint to the image" << std::endl
79 << " u\tUndo the last edit to the annotation tools" << std::endl
80 << std::endl << "Mouse buttons:" << std::endl 93 << std::endl << "Mouse buttons:" << std::endl
81 << " left \tChange windowing, or edit annotation" << std::endl 94 << " left \tChange windowing, or edit annotation" << std::endl
82 << " center\tMove the viewpoint, or edit annotation" << std::endl 95 << " center\tMove the viewpoint, or edit annotation" << std::endl
83 << " right \tZoom, or edit annotation" << std::endl 96 << " right \tZoom, or edit annotation" << std::endl
84 << std::endl; 97 << std::endl;
142 155
143 //Orthanc::Logging::EnableInfoLevel(true); 156 //Orthanc::Logging::EnableInfoLevel(true);
144 //Orthanc::Logging::EnableTraceLevel(true); 157 //Orthanc::Logging::EnableTraceLevel(true);
145 158
146 { 159 {
147 160 #if SAMPLE_USE_OPENGL == 1
148 #if 0
149 boost::shared_ptr<OrthancStone::SdlViewport> viewport = 161 boost::shared_ptr<OrthancStone::SdlViewport> viewport =
150 OrthancStone::SdlOpenGLViewport::Create("Stone of Orthanc", 800, 600); 162 OrthancStone::SdlOpenGLViewport::Create("Stone of Orthanc", 800, 600);
151 #else 163 #else
152 boost::shared_ptr<OrthancStone::SdlViewport> viewport = 164 boost::shared_ptr<OrthancStone::SdlViewport> viewport =
153 OrthancStone::SdlCairoViewport::Create("Stone of Orthanc", 800, 600); 165 OrthancStone::SdlCairoViewport::Create("Stone of Orthanc", 800, 600);
154 #endif 166 #endif
155 167
168 #if SAMPLE_USE_ANNOTATIONS_LAYER != 1
156 boost::shared_ptr<OrthancStone::UndoStack> undoStack(new OrthancStone::UndoStack); 169 boost::shared_ptr<OrthancStone::UndoStack> undoStack(new OrthancStone::UndoStack);
170 #endif
157 171
158 OrthancStone::GenericLoadersContext context(1, 4, 1); 172 OrthancStone::GenericLoadersContext context(1, 4, 1);
159 173
160 Orthanc::WebServiceParameters orthancWebService; 174 Orthanc::WebServiceParameters orthancWebService;
161 orthancWebService.SetUrl(orthancUrl); 175 orthancWebService.SetUrl(orthancUrl);
168 std::string font; 182 std::string font;
169 Orthanc::EmbeddedResources::GetFileResource(font, Orthanc::EmbeddedResources::UBUNTU_FONT); 183 Orthanc::EmbeddedResources::GetFileResource(font, Orthanc::EmbeddedResources::UBUNTU_FONT);
170 184
171 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock()); 185 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
172 lock->GetCompositor().SetFont(0, font, 16, Orthanc::Encoding_Latin1); 186 lock->GetCompositor().SetFont(0, font, 16, Orthanc::Encoding_Latin1);
173 //lock->GetController().SetUndoStack(undoStack); 187
188 #if SAMPLE_USE_ANNOTATIONS_LAYER != 1
189 lock->GetController().SetUndoStack(undoStack);
190 #endif
174 } 191 }
175 192
193 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
194 OrthancStone::AnnotationsSceneLayer annotations(10);
195 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Edit);
196 #else
176 ActiveTool activeTool = ActiveTool_None; 197 ActiveTool activeTool = ActiveTool_None;
177 198
178 boost::shared_ptr<OrthancStone::LineMeasureTool> lineMeasureTool(OrthancStone::LineMeasureTool::Create(viewport)); 199 boost::shared_ptr<OrthancStone::LineMeasureTool> lineMeasureTool(OrthancStone::LineMeasureTool::Create(viewport));
179 bool lineMeasureFirst = true; 200 bool lineMeasureFirst = true;
180 lineMeasureTool->Disable(); 201 lineMeasureTool->Disable();
181 202
182 boost::shared_ptr<OrthancStone::AngleMeasureTool> angleMeasureTool(OrthancStone::AngleMeasureTool::Create(viewport)); 203 boost::shared_ptr<OrthancStone::AngleMeasureTool> angleMeasureTool(OrthancStone::AngleMeasureTool::Create(viewport));
183 bool angleMeasureFirst = true; 204 bool angleMeasureFirst = true;
184 angleMeasureTool->Disable(); 205 angleMeasureTool->Disable();
185 206 #endif
186 OrthancStone::AnnotationsSceneLayer annotations(10);
187 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Angle);
188
189 {
190 Json::Value v;
191 annotations.Serialize(v);
192 std::cout << v.toStyledString() << std::endl;
193 annotations.Clear();
194 annotations.Unserialize(v);
195 }
196 207
197 boost::shared_ptr<SdlSimpleViewerApplication> application( 208 boost::shared_ptr<SdlSimpleViewerApplication> application(
198 SdlSimpleViewerApplication::Create(context, viewport)); 209 SdlSimpleViewerApplication::Create(context, viewport));
199 210
200 OrthancStone::DicomSource source; 211 OrthancStone::DicomSource source;
252 263
253 case SDLK_q: 264 case SDLK_q:
254 stop = true; 265 stop = true;
255 break; 266 break;
256 267
268 #if SAMPLE_USE_ANNOTATIONS_LAYER != 1
257 case SDLK_u: 269 case SDLK_u:
258 { 270 {
259 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock()); 271 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
260 if (lock->GetController().CanUndo()) 272 if (lock->GetController().CanUndo())
261 { 273 {
262 lock->GetController().Undo(); 274 lock->GetController().Undo();
263 } 275 }
264 break; 276 break;
265 } 277 }
266 278 #endif
279
280 #if SAMPLE_USE_ANNOTATIONS_LAYER != 1
267 case SDLK_r: 281 case SDLK_r:
268 { 282 {
269 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock()); 283 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
270 if (lock->GetController().CanRedo()) 284 if (lock->GetController().CanRedo())
271 { 285 {
272 lock->GetController().Redo(); 286 lock->GetController().Redo();
273 } 287 }
274 break; 288 break;
275 } 289 }
290 #endif
291
292 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
293 case SDLK_c:
294 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Circle);
295 break;
296 #endif
297
298 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
299 case SDLK_e:
300 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Edit);
301 break;
302 #endif
303
304 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
305 case SDLK_d:
306 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Erase);
307 break;
308 #endif
276 309
277 case SDLK_l: 310 case SDLK_l:
311 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
312 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Segment);
313 #else
278 if (activeTool == ActiveTool_Line) 314 if (activeTool == ActiveTool_Line)
279 { 315 {
280 lineMeasureTool->Disable(); 316 lineMeasureTool->Disable();
281 activeTool = ActiveTool_None; 317 activeTool = ActiveTool_None;
282 } 318 }
297 333
298 lineMeasureTool->Enable(); 334 lineMeasureTool->Enable();
299 angleMeasureTool->Disable(); 335 angleMeasureTool->Disable();
300 activeTool = ActiveTool_Line; 336 activeTool = ActiveTool_Line;
301 } 337 }
338 #endif
302 break; 339 break;
303 340
304 case SDLK_a: 341 case SDLK_a:
342 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
343 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Angle);
344 #else
305 if (activeTool == ActiveTool_Angle) 345 if (activeTool == ActiveTool_Angle)
306 { 346 {
307 angleMeasureTool->Disable(); 347 angleMeasureTool->Disable();
308 activeTool = ActiveTool_None; 348 activeTool = ActiveTool_None;
309 } 349 }
331 371
332 lineMeasureTool->Disable(); 372 lineMeasureTool->Disable();
333 angleMeasureTool->Enable(); 373 angleMeasureTool->Enable();
334 activeTool = ActiveTool_Angle; 374 activeTool = ActiveTool_Angle;
335 } 375 }
376 #endif
336 break; 377 break;
337 378
338 default: 379 default:
339 break; 380 break;
340 } 381 }
353 switch (event.type) 394 switch (event.type)
354 { 395 {
355 case SDL_MOUSEBUTTONDOWN: 396 case SDL_MOUSEBUTTONDOWN:
356 { 397 {
357 boost::shared_ptr<OrthancStone::IFlexiblePointerTracker> t; 398 boost::shared_ptr<OrthancStone::IFlexiblePointerTracker> t;
358 399
400 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
359 if (p.GetMouseButton() == OrthancStone::MouseButton_Left) 401 if (p.GetMouseButton() == OrthancStone::MouseButton_Left)
360 { 402 {
361 t.reset(annotations.CreateTracker(p.GetMainPosition(), lock->GetController().GetScene())); 403 t.reset(annotations.CreateTracker(p.GetMainPosition(), lock->GetController().GetScene()));
362 } 404 }
363 405 #else
364 if (t.get() == NULL) 406 if (t.get() == NULL)
365 { 407 {
366 switch (activeTool) 408 switch (activeTool)
367 { 409 {
368 case ActiveTool_Angle: 410 case ActiveTool_Angle:
378 420
379 default: 421 default:
380 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 422 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
381 } 423 }
382 } 424 }
425 #endif
383 426
384 if (t.get() != NULL) 427 if (t.get() != NULL)
385 { 428 {
386 lock->GetController().AcquireActiveTracker(t); 429 lock->GetController().AcquireActiveTracker(t);
387 } 430 }
394 lock->Invalidate(); 437 lock->Invalidate();
395 break; 438 break;
396 } 439 }
397 440
398 case SDL_MOUSEMOTION: 441 case SDL_MOUSEMOTION:
442 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
399 if (lock->GetController().HandleMouseMove(p)) 443 if (lock->GetController().HandleMouseMove(p))
400 { 444 {
401 lock->Invalidate(); 445 lock->Invalidate();
402 if (annotations.ClearHover()) 446 if (annotations.ClearHover())
403 { 447 {
409 if (annotations.SetMouseHover(p.GetMainPosition(), lock->GetController().GetScene())) 453 if (annotations.SetMouseHover(p.GetMainPosition(), lock->GetController().GetScene()))
410 { 454 {
411 paint = true; 455 paint = true;
412 } 456 }
413 } 457 }
458 #else
459 if (lock->GetController().HandleMouseMove(p))
460 {
461 lock->Invalidate();
462 paint = true;
463 }
464 #endif
414 break; 465 break;
415 466
416 case SDL_MOUSEBUTTONUP: 467 case SDL_MOUSEBUTTONUP:
417 lock->GetController().HandleMouseRelease(p); 468 lock->GetController().HandleMouseRelease(p);
418 lock->Invalidate(); 469 lock->Invalidate();
425 } 476 }
426 } 477 }
427 478
428 if (paint) 479 if (paint)
429 { 480 {
481 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
430 { 482 {
431 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock()); 483 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
432 annotations.Render(lock->GetController().GetScene()); 484 annotations.Render(lock->GetController().GetScene());
433 } 485 }
486 #endif
434 487
435 viewport->Paint(); 488 viewport->Paint();
436 } 489 }
437 490
438 // Small delay to avoid using 100% of CPU 491 // Small delay to avoid using 100% of CPU