comparison Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp @ 1681:f2e8b3ac1dcd

handling multiple windowing presets in the Stone web viewer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 24 Nov 2020 18:08:07 +0100
parents 03afa09cfcf1
children 84fe7089ccaa
comparison
equal deleted inserted replaced
1680:03afa09cfcf1 1681:f2e8b3ac1dcd
92 #include <WebAssemblyCairoViewport.h> 92 #include <WebAssemblyCairoViewport.h>
93 #include <WebAssemblyLoadersContext.h> 93 #include <WebAssemblyLoadersContext.h>
94 #include <WebGLViewport.h> 94 #include <WebGLViewport.h>
95 95
96 96
97 #include <boost/math/special_functions/round.hpp>
97 #include <boost/make_shared.hpp> 98 #include <boost/make_shared.hpp>
98 #include <stdio.h> 99 #include <stdio.h>
99 100
100 101
101 #if !defined(STONE_WEB_VIEWER_EXPORT) 102 #if !defined(STONE_WEB_VIEWER_EXPORT)
1100 const Orthanc::DicomMap& dicom = message.GetResources()->GetResource(0); 1101 const Orthanc::DicomMap& dicom = message.GetResources()->GetResource(0);
1101 1102
1102 { 1103 {
1103 OrthancStone::DicomInstanceParameters params(dicom); 1104 OrthancStone::DicomInstanceParameters params(dicom);
1104 1105
1106 GetViewport().windowingPresetCenters_.resize(params.GetWindowingPresetsCount());
1107 GetViewport().windowingPresetWidths_.resize(params.GetWindowingPresetsCount());
1108
1105 for (size_t i = 0; i < params.GetWindowingPresetsCount(); i++) 1109 for (size_t i = 0; i < params.GetWindowingPresetsCount(); i++)
1106 { 1110 {
1107 LOG(INFO) << "Preset windowing " << i << "/" << params.GetWindowingPresetsCount() 1111 LOG(INFO) << "Preset windowing " << (i + 1) << "/" << params.GetWindowingPresetsCount()
1108 << ": " << params.GetWindowingPresetCenter(i) 1112 << ": " << params.GetWindowingPresetCenter(i)
1109 << "," << params.GetWindowingPresetWidth(i); 1113 << "," << params.GetWindowingPresetWidth(i);
1114
1115 GetViewport().windowingPresetCenters_[i] = params.GetWindowingPresetCenter(i);
1116 GetViewport().windowingPresetWidths_[i] = params.GetWindowingPresetWidth(i);
1110 } 1117 }
1111 1118
1112 // TODO - WINDOWING 1119 if (params.GetWindowingPresetsCount() == 0)
1113 if (params.GetWindowingPresetsCount() > 0)
1114 {
1115 GetViewport().presetWindowingCenter_ = params.GetWindowingPresetCenter(0);
1116 GetViewport().presetWindowingWidth_ = params.GetWindowingPresetWidth(0);
1117
1118 GetViewport().windowingCenter_ = params.GetWindowingPresetCenter(0);
1119 GetViewport().windowingWidth_ = params.GetWindowingPresetWidth(0);
1120 }
1121 else
1122 { 1120 {
1123 LOG(INFO) << "No preset windowing"; 1121 LOG(INFO) << "No preset windowing";
1124 GetViewport().ResetWindowingPreset();
1125 } 1122 }
1123
1124 GetViewport().SetWindowingPreset();
1126 } 1125 }
1127 1126
1128 uint32_t cineRate; 1127 uint32_t cineRate;
1129 if (dicom.ParseUnsignedInteger32(cineRate, Orthanc::DICOM_TAG_CINE_RATE) && 1128 if (dicom.ParseUnsignedInteger32(cineRate, Orthanc::DICOM_TAG_CINE_RATE) &&
1130 cineRate > 0) 1129 cineRate > 0)
1365 boost::shared_ptr<FramesCache> framesCache_; 1364 boost::shared_ptr<FramesCache> framesCache_;
1366 std::unique_ptr<OrthancStone::SortedFrames> frames_; 1365 std::unique_ptr<OrthancStone::SortedFrames> frames_;
1367 std::unique_ptr<SeriesCursor> cursor_; 1366 std::unique_ptr<SeriesCursor> cursor_;
1368 float windowingCenter_; 1367 float windowingCenter_;
1369 float windowingWidth_; 1368 float windowingWidth_;
1370 float presetWindowingCenter_; 1369 std::vector<float> windowingPresetCenters_;
1371 float presetWindowingWidth_; 1370 std::vector<float> windowingPresetWidths_;
1372 unsigned int cineRate_; 1371 unsigned int cineRate_;
1373 bool inverted_; 1372 bool inverted_;
1374 bool flipX_; 1373 bool flipX_;
1375 bool flipY_; 1374 bool flipY_;
1376 bool fitNextContent_; 1375 bool fitNextContent_;
1414 } 1413 }
1415 } 1414 }
1416 } 1415 }
1417 1416
1418 1417
1419 void ResetWindowingPreset()
1420 {
1421 presetWindowingCenter_ = 128;
1422 presetWindowingWidth_ = 256;
1423
1424 windowingCenter_ = presetWindowingCenter_;
1425 windowingWidth_ = presetWindowingWidth_;
1426
1427 inverted_ = false;
1428 }
1429
1430
1431 void ClearViewport() 1418 void ClearViewport()
1432 { 1419 {
1433 { 1420 {
1434 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport_->Lock()); 1421 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport_->Lock());
1435 lock->GetController().GetScene().DeleteLayer(LAYER_TEXTURE); 1422 lock->GetController().GetScene().DeleteLayer(LAYER_TEXTURE);
1792 1779
1793 emscripten_set_wheel_callback(viewport_->GetCanvasCssSelector().c_str(), this, true, OnWheel); 1780 emscripten_set_wheel_callback(viewport_->GetCanvasCssSelector().c_str(), this, true, OnWheel);
1794 emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, OnKey); 1781 emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, OnKey);
1795 emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, OnKey); 1782 emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, OnKey);
1796 1783
1797 ResetWindowingPreset(); 1784 SetWindowingPreset();
1798 } 1785 }
1799 1786
1800 static EM_BOOL OnKey(int eventType, 1787 static EM_BOOL OnKey(int eventType,
1801 const EmscriptenKeyboardEvent *event, 1788 const EmscriptenKeyboardEvent *event,
1802 void *userData) 1789 void *userData)
1894 1881
1895 flipX_ = false; 1882 flipX_ = false;
1896 flipY_ = false; 1883 flipY_ = false;
1897 fitNextContent_ = true; 1884 fitNextContent_ = true;
1898 cineRate_ = DEFAULT_CINE_RATE; 1885 cineRate_ = DEFAULT_CINE_RATE;
1899 1886 inverted_ = false;
1887
1900 frames_.reset(frames); 1888 frames_.reset(frames);
1901 cursor_.reset(new SeriesCursor(frames_->GetFramesCount())); 1889 cursor_.reset(new SeriesCursor(frames_->GetFramesCount()));
1902 1890
1903 LOG(INFO) << "Number of frames in series: " << frames_->GetFramesCount(); 1891 LOG(INFO) << "Number of frames in series: " << frames_->GetFramesCount();
1904 1892
1905 ResetWindowingPreset(); 1893 SetWindowingPreset();
1906 ClearViewport(); 1894 ClearViewport();
1907 prefetchQueue_.clear(); 1895 prefetchQueue_.clear();
1908 1896
1909 if (observer_.get() != NULL) 1897 if (observer_.get() != NULL)
1910 { 1898 {
2129 } 2117 }
2130 2118
2131 2119
2132 void SetWindowingPreset() 2120 void SetWindowingPreset()
2133 { 2121 {
2134 SetWindowing(presetWindowingCenter_, presetWindowingWidth_); 2122 assert(windowingPresetCenters_.size() == windowingPresetWidths_.size());
2123
2124 if (windowingPresetCenters_.empty())
2125 {
2126 windowingCenter_ = 128;
2127 windowingWidth_ = 256;
2128 }
2129 else
2130 {
2131 windowingCenter_ = windowingPresetCenters_[0];
2132 windowingWidth_ = windowingPresetWidths_[0];
2133 }
2135 } 2134 }
2136 2135
2137 void SetWindowing(float windowingCenter, 2136 void SetWindowing(float windowingCenter,
2138 float windowingWidth) 2137 float windowingWidth)
2139 { 2138 {
2331 return cineRate_; 2330 return cineRate_;
2332 } 2331 }
2333 2332
2334 void FormatWindowingPresets(Json::Value& target) const 2333 void FormatWindowingPresets(Json::Value& target) const
2335 { 2334 {
2335 assert(windowingPresetCenters_.size() == windowingPresetWidths_.size());
2336
2336 target = Json::arrayValue; 2337 target = Json::arrayValue;
2338
2339 for (size_t i = 0; i < windowingPresetCenters_.size(); i++)
2340 {
2341 const float c = windowingPresetCenters_[i];
2342 const float w = windowingPresetWidths_[i];
2343
2344 std::string name = "Preset";
2345 if (windowingPresetCenters_.size() > 1)
2346 {
2347 name += " " + boost::lexical_cast<std::string>(i + 1);
2348 }
2349
2350 Json::Value preset = Json::objectValue;
2351 preset["name"] = name;
2352 preset["info"] = ("C " + boost::lexical_cast<std::string>(boost::math::iround(c)) +
2353 ", W " + boost::lexical_cast<std::string>(boost::math::iround(w)));
2354 preset["center"] = c;
2355 preset["width"] = w;
2356
2357 target.append(preset);
2358 }
2337 } 2359 }
2338 }; 2360 };
2339 2361
2340 2362
2341 2363
2823 EXTERN_CATCH_EXCEPTIONS; 2845 EXTERN_CATCH_EXCEPTIONS;
2824 } 2846 }
2825 2847
2826 2848
2827 EMSCRIPTEN_KEEPALIVE 2849 EMSCRIPTEN_KEEPALIVE
2828 void SetWindowingPreset(const char* canvas)
2829 {
2830 try
2831 {
2832 GetViewport(canvas)->SetWindowingPreset();
2833 }
2834 EXTERN_CATCH_EXCEPTIONS;
2835 }
2836
2837
2838 EMSCRIPTEN_KEEPALIVE
2839 void SetWindowing(const char* canvas, 2850 void SetWindowing(const char* canvas,
2840 int center, 2851 int center,
2841 int width) 2852 int width)
2842 { 2853 {
2843 try 2854 try