Mercurial > hg > orthanc-stone
comparison Samples/Common/RtViewer.cpp @ 1393:27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
other viewports ongoing
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 29 Apr 2020 15:54:18 +0200 |
parents | ffdb82850e98 |
children |
comparison
equal
deleted
inserted
replaced
1392:ffdb82850e98 | 1393:27e0a00bd3e8 |
---|---|
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 // Sample app | 21 // Sample app |
22 #include "RtViewer.h" | 22 #include "RtViewer.h" |
23 #include "SampleHelpers.h" | |
23 | 24 |
24 // Stone of Orthanc | 25 // Stone of Orthanc |
25 #include <Framework/StoneInitialization.h> | 26 #include <Framework/StoneInitialization.h> |
26 #include <Framework/Scene2D/CairoCompositor.h> | 27 #include <Framework/Scene2D/CairoCompositor.h> |
27 #include <Framework/Scene2D/ColorTextureSceneLayer.h> | 28 #include <Framework/Scene2D/ColorTextureSceneLayer.h> |
37 #include <Framework/Scene2DViewport/MeasureTool.h> | 38 #include <Framework/Scene2DViewport/MeasureTool.h> |
38 #include <Framework/Scene2DViewport/PredeclaredTypes.h> | 39 #include <Framework/Scene2DViewport/PredeclaredTypes.h> |
39 #include <Framework/Volumes/VolumeSceneLayerSource.h> | 40 #include <Framework/Volumes/VolumeSceneLayerSource.h> |
40 | 41 |
41 #include <Framework/Oracle/GetOrthancWebViewerJpegCommand.h> | 42 #include <Framework/Oracle/GetOrthancWebViewerJpegCommand.h> |
42 #include <Framework/Oracle/ThreadedOracle.h> | |
43 #include <Framework/Scene2D/GrayscaleStyleConfigurator.h> | 43 #include <Framework/Scene2D/GrayscaleStyleConfigurator.h> |
44 #include <Framework/Scene2D/LookupTableStyleConfigurator.h> | 44 #include <Framework/Scene2D/LookupTableStyleConfigurator.h> |
45 #include <Framework/Volumes/DicomVolumeImageMPRSlicer.h> | 45 #include <Framework/Volumes/DicomVolumeImageMPRSlicer.h> |
46 #include <Framework/StoneException.h> | 46 #include <Framework/StoneException.h> |
47 | 47 |
48 // Orthanc | 48 // Orthanc |
49 #include <Core/Images/Image.h> | |
50 #include <Core/Images/ImageProcessing.h> | |
51 #include <Core/Images/PngWriter.h> | |
52 #include <Core/Logging.h> | 49 #include <Core/Logging.h> |
53 #include <Core/OrthancException.h> | 50 #include <Core/OrthancException.h> |
54 | 51 |
55 // System | 52 // System |
56 #include <boost/shared_ptr.hpp> | 53 #include <boost/shared_ptr.hpp> |
247 : currentTool_(RtViewerGuiTool_Rotate) | 244 : currentTool_(RtViewerGuiTool_Rotate) |
248 , undoStack_(new UndoStack) | 245 , undoStack_(new UndoStack) |
249 , currentPlane_(0) | 246 , currentPlane_(0) |
250 , projection_(VolumeProjection_Coronal) | 247 , projection_(VolumeProjection_Coronal) |
251 { | 248 { |
252 // False means we do NOT let Windows treat this as a legacy application that needs to be scaled | 249 // the viewport hosts the scene |
253 viewport_ = SdlOpenGLViewport::Create("CT RTDOSE RTSTRUCT viewer", 1024, 1024, false); | 250 CreateViewport(); |
254 | 251 |
255 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); | 252 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); |
256 ViewportController& controller = lock->GetController(); | 253 ViewportController& controller = lock->GetController(); |
257 Scene2D& scene = controller.GetScene(); | 254 Scene2D& scene = controller.GetScene(); |
258 | 255 |
324 { | 321 { |
325 activeTracker_->Cancel(); | 322 activeTracker_->Cancel(); |
326 activeTracker_.reset(); | 323 activeTracker_.reset(); |
327 } | 324 } |
328 } | 325 } |
329 | 326 |
330 void RtViewerApp::TakeScreenshot(const std::string& target, | |
331 unsigned int canvasWidth, | |
332 unsigned int canvasHeight) | |
333 { | |
334 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); | |
335 ViewportController& controller = lock->GetController(); | |
336 Scene2D& scene = controller.GetScene(); | |
337 | |
338 CairoCompositor compositor(canvasWidth, canvasHeight); | |
339 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, FONT_SIZE_0, Orthanc::Encoding_Latin1); | |
340 compositor.Refresh(scene); | |
341 | |
342 Orthanc::ImageAccessor canvas; | |
343 compositor.GetCanvas().GetReadOnlyAccessor(canvas); | |
344 | |
345 Orthanc::Image png(Orthanc::PixelFormat_RGB24, canvas.GetWidth(), canvas.GetHeight(), false); | |
346 Orthanc::ImageProcessing::Convert(png, canvas); | |
347 | |
348 Orthanc::PngWriter writer; | |
349 writer.WriteToFile(target, png); | |
350 } | |
351 | |
352 boost::shared_ptr<IFlexiblePointerTracker> RtViewerApp::TrackerHitTest(const PointerEvent& e) | |
353 { | |
354 // std::vector<boost::shared_ptr<MeasureTool>> measureTools_; | |
355 return boost::shared_ptr<IFlexiblePointerTracker>(); | |
356 } | |
357 | |
358 void RtViewerApp::PrepareLoadersAndSlicers() | 327 void RtViewerApp::PrepareLoadersAndSlicers() |
359 { | 328 { |
360 | 329 |
361 //{ | 330 //{ |
362 // Orthanc::WebServiceParameters p; | 331 // Orthanc::WebServiceParameters p; |
367 | 336 |
368 { | 337 { |
369 // "true" means use progressive quality (jpeg 50 --> jpeg 90 --> 16-bit raw) | 338 // "true" means use progressive quality (jpeg 50 --> jpeg 90 --> 16-bit raw) |
370 // "false" means only using hi quality | 339 // "false" means only using hi quality |
371 // TODO: add flag for quality | 340 // TODO: add flag for quality |
372 ctLoader_ = OrthancSeriesVolumeProgressiveLoader::Create(*loadersContext_, ctVolume_, false); | 341 ctLoader_ = OrthancSeriesVolumeProgressiveLoader::Create(*loadersContext_, ctVolume_, true); |
373 | 342 |
374 // we need to store the CT loader to ask from geometry details later on when geometry is loaded | 343 // we need to store the CT loader to ask from geometry details later on when geometry is loaded |
375 geometryProvider_ = ctLoader_; | 344 geometryProvider_ = ctLoader_; |
376 | 345 |
377 doseLoader_ = OrthancMultiframeVolumeLoader::Create(*loadersContext_, doseVolume_); | 346 doseLoader_ = OrthancMultiframeVolumeLoader::Create(*loadersContext_, doseVolume_); |
419 } | 388 } |
420 | 389 |
421 this->SetStructureSet(LAYER_POSITION + 2, rtstructLoader_); | 390 this->SetStructureSet(LAYER_POSITION + 2, rtstructLoader_); |
422 | 391 |
423 #if 1 | 392 #if 1 |
393 ORTHANC_ASSERT(HasArgument("ctseries") && HasArgument("rtdose") && HasArgument("rtstruct")); | |
394 | |
424 LOG(INFO) << "About to load:"; | 395 LOG(INFO) << "About to load:"; |
425 LOG(INFO) << " CT : " << ctSeriesId_;; | 396 LOG(INFO) << " CT : " << GetArgument("ctseries"); |
426 LOG(INFO) << " RTDOSE : " << doseInstanceId_; | 397 LOG(INFO) << " RTDOSE : " << GetArgument("rtdose"); |
427 LOG(INFO) << " RTSTRUCT : " << rtStructInstanceId_; | 398 LOG(INFO) << " RTSTRUCT : " << GetArgument("rtstruct"); |
428 ctLoader_->LoadSeries(ctSeriesId_); | 399 ctLoader_->LoadSeries(GetArgument("ctseries")); |
429 doseLoader_->LoadInstance(doseInstanceId_); | 400 doseLoader_->LoadInstance(GetArgument("rtdose")); |
430 rtstructLoader_->LoadInstanceFullVisibility(rtStructInstanceId_); | 401 rtstructLoader_->LoadInstanceFullVisibility(GetArgument("rtstruct")); |
431 | 402 |
432 #elif 0 | 403 #elif 0 |
433 /* | 404 /* |
434 BGO data | 405 BGO data |
435 http://localhost:8042/twiga-orthanc-viewer-demo/twiga-orthanc-viewer-demo.html?ct-series=a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa | 406 http://localhost:8042/twiga-orthanc-viewer-demo/twiga-orthanc-viewer-demo.html?ct-series=a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa |
545 Scene2D& scene = controller.GetScene(); | 516 Scene2D& scene = controller.GetScene(); |
546 | 517 |
547 structLayerSource_.reset(new OrthancStone::VolumeSceneLayerSource(scene, depth, volume)); | 518 structLayerSource_.reset(new OrthancStone::VolumeSceneLayerSource(scene, depth, volume)); |
548 } | 519 } |
549 | 520 |
521 void RtViewerApp::SetArgument(const std::string& key, const std::string& value) | |
522 { | |
523 if (key == "loglevel") | |
524 OrthancStoneHelpers::SetLogLevel(value); | |
525 else | |
526 arguments_[key] = value; | |
527 } | |
528 | |
529 const std::string& RtViewerApp::GetArgument(const std::string& key) const | |
530 { | |
531 ORTHANC_ASSERT(HasArgument(key)); | |
532 return arguments_.at(key); | |
533 } | |
534 bool RtViewerApp::HasArgument(const std::string& key) const | |
535 { | |
536 return (arguments_.find(key) != arguments_.end()); | |
537 } | |
550 | 538 |
551 void RtViewerApp::SetInfoDisplayMessage( | 539 void RtViewerApp::SetInfoDisplayMessage( |
552 std::string key, std::string value) | 540 std::string key, std::string value) |
553 { | 541 { |
554 if (value == "") | 542 if (value == "") |