comparison Samples/Sdl/TrackerSampleApp.cpp @ 660:cb3b76d16234

Added info display map to the app + global logging function + fixed bisecting algo to display angle measure text label
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 14 May 2019 19:38:51 +0200
parents 002d9562c8f5
children 970949ff868a 8b6adfb62a2f
comparison
equal deleted inserted replaced
659:68b5688241d5 660:cb3b76d16234
80 printf("Current tool is now: %s\n", MeasureToolToString(currentTool_)); 80 printf("Current tool is now: %s\n", MeasureToolToString(currentTool_));
81 } 81 }
82 82
83 void TrackerSampleApp::DisplayInfoText() 83 void TrackerSampleApp::DisplayInfoText()
84 { 84 {
85 char buf[256]; 85 // do not try to use stuff too early!
86 sprintf(buf, "INFO TEXT\n*** INFO TEXT ***\ntoto tata tutu titi\nprrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrout"); 86 if (compositor_.get() == NULL)
87 return;
88
89 std::stringstream msg;
90 for (auto kv : infoTextMap_)
91 {
92 msg << kv.first << " : " << kv.second << std::endl;
93 }
94 auto msgS = msg.str();
87 95
88 TextSceneLayer* layerP = NULL; 96 TextSceneLayer* layerP = NULL;
89 if (scene_.HasLayer(FIXED_INFOTEXT_LAYER_ZINDEX)) 97 if (scene_.HasLayer(FIXED_INFOTEXT_LAYER_ZINDEX))
90 { 98 {
91 TextSceneLayer& layer = dynamic_cast<TextSceneLayer&>( 99 TextSceneLayer& layer = dynamic_cast<TextSceneLayer&>(
96 { 104 {
97 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer); 105 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer);
98 layerP = layer.get(); 106 layerP = layer.get();
99 layer->SetColor(0, 255, 0); 107 layer->SetColor(0, 255, 0);
100 layer->SetFontIndex(1); 108 layer->SetFontIndex(1);
101 layer->SetText(buf);
102 layer->SetBorder(20); 109 layer->SetBorder(20);
103 layer->SetAnchor(BitmapAnchor_TopLeft); 110 layer->SetAnchor(BitmapAnchor_TopLeft);
104 //layer->SetPosition(0,0); 111 //layer->SetPosition(0,0);
105 scene_.SetLayer(FIXED_INFOTEXT_LAYER_ZINDEX, layer.release()); 112 scene_.SetLayer(FIXED_INFOTEXT_LAYER_ZINDEX, layer.release());
106 } 113 }
107 // position the fixed info text in the upper right corner 114 // position the fixed info text in the upper right corner
108 layerP->SetText(buf); 115 layerP->SetText(msgS.c_str());
109 double cX = compositor_->GetCanvasWidth() * (-0.5); 116 double cX = compositor_->GetCanvasWidth() * (-0.5);
110 double cY = compositor_->GetCanvasHeight() * (-0.5); 117 double cY = compositor_->GetCanvasHeight() * (-0.5);
111 scene_.GetCanvasToSceneTransform().Apply(cX,cY); 118 scene_.GetCanvasToSceneTransform().Apply(cX,cY);
112 layerP->SetPosition(cX, cY); 119 layerP->SetPosition(cX, cY);
113 } 120 }
260 } 267 }
261 268
262 269
263 void TrackerSampleApp::OnSceneTransformChanged(const Scene2D::SceneTransformChanged& message) 270 void TrackerSampleApp::OnSceneTransformChanged(const Scene2D::SceneTransformChanged& message)
264 { 271 {
265 // do not try to call this too early! 272 DisplayInfoText();
266 if(compositor_.get() != NULL)
267 DisplayInfoText();
268 } 273 }
269 274
270 FlexiblePointerTrackerPtr TrackerSampleApp::CreateSuitableTracker( 275 FlexiblePointerTrackerPtr TrackerSampleApp::CreateSuitableTracker(
271 const SDL_Event & event, 276 const SDL_Event & event,
272 const PointerEvent & e) 277 const PointerEvent & e)
340 return NULL; 345 return NULL;
341 } 346 }
342 } 347 }
343 348
344 349
350 TrackerSampleApp::TrackerSampleApp(MessageBroker& broker) : IObserver(broker)
351 , currentTool_(GuiTool_Rotate)
352 , scene_(broker)
353 {
354 scene_.RegisterObserverCallback(
355 new Callable<TrackerSampleApp, Scene2D::SceneTransformChanged>
356 (*this, &TrackerSampleApp::OnSceneTransformChanged));
357
358 TEXTURE_2x2_1_ZINDEX = 1;
359 TEXTURE_1x1_ZINDEX = 2;
360 TEXTURE_2x2_2_ZINDEX = 3;
361 LINESET_1_ZINDEX = 4;
362 LINESET_2_ZINDEX = 5;
363 FLOATING_INFOTEXT_LAYER_ZINDEX = 6;
364 FIXED_INFOTEXT_LAYER_ZINDEX = 7;
365
366
367 }
368
345 void TrackerSampleApp::PrepareScene() 369 void TrackerSampleApp::PrepareScene()
346 { 370 {
347 // Texture of 2x2 size 371 // Texture of 2x2 size
348 { 372 {
349 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false); 373 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false);
541 SDL_Delay(1); 565 SDL_Delay(1);
542 } 566 }
543 compositor_.reset(NULL); 567 compositor_.reset(NULL);
544 } 568 }
545 569
546 570 void TrackerSampleApp::SetInfoDisplayMessage(
571 std::string key, std::string value)
572 {
573 if (value == "")
574 infoTextMap_.erase(key);
575 else
576 infoTextMap_[key] = value;
577 DisplayInfoText();
578 }
547 579
548 } 580 }