comparison Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp @ 1996:6e4ef6e3b2bf

linear interpolation of images can be turned off in the user preferences
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 01 Nov 2022 19:41:03 +0100
parents 317a53d4fdc6
children 1fa3f484008e
comparison
equal deleted inserted replaced
1995:f2a094fa8c33 1996:6e4ef6e3b2bf
2020 // The coordinates of Stone annotations are expressed in 2D 2020 // The coordinates of Stone annotations are expressed in 2D
2021 // coordinates of the current texture, with (0,0) corresponding to 2021 // coordinates of the current texture, with (0,0) corresponding to
2022 // the center of the top-left pixel 2022 // the center of the top-left pixel
2023 boost::shared_ptr<OrthancStone::AnnotationsSceneLayer> stoneAnnotations_; 2023 boost::shared_ptr<OrthancStone::AnnotationsSceneLayer> stoneAnnotations_;
2024 2024
2025 bool linearInterpolation_;
2026
2025 2027
2026 void ScheduleNextPrefetch() 2028 void ScheduleNextPrefetch()
2027 { 2029 {
2028 while (!prefetchQueue_.empty()) 2030 while (!prefetchQueue_.empty())
2029 { 2031 {
2157 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); 2159 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
2158 } 2160 }
2159 2161
2160 assert(layer.get() != NULL); 2162 assert(layer.get() != NULL);
2161 2163
2162 layer->SetLinearInterpolation(true); 2164 layer->SetLinearInterpolation(linearInterpolation_);
2163 2165
2164 double pixelSpacingX, pixelSpacingY; 2166 double pixelSpacingX, pixelSpacingY;
2165 2167
2166 if (instance.HasPixelSpacing()) 2168 if (instance.HasPixelSpacing())
2167 { 2169 {
2211 { 2213 {
2212 OverlaysRegistry::Accessor accessor(OverlaysRegistry::GetInstance(), instance.GetSopInstanceUid()); 2214 OverlaysRegistry::Accessor accessor(OverlaysRegistry::GetInstance(), instance.GetSopInstanceUid());
2213 if (accessor.IsValid()) 2215 if (accessor.IsValid())
2214 { 2216 {
2215 overlay.reset(accessor.CreateTexture()); 2217 overlay.reset(accessor.CreateTexture());
2218 overlay->SetLinearInterpolation(false);
2216 } 2219 }
2217 } 2220 }
2218 2221
2219 std::unique_ptr<OrthancStone::MacroSceneLayer> annotationsOsiriX; 2222 std::unique_ptr<OrthancStone::MacroSceneLayer> annotationsOsiriX;
2220 2223
2505 2508
2506 ViewerViewport(OrthancStone::WebAssemblyLoadersContext& context, 2509 ViewerViewport(OrthancStone::WebAssemblyLoadersContext& context,
2507 const OrthancStone::DicomSource& source, 2510 const OrthancStone::DicomSource& source,
2508 const std::string& canvas, 2511 const std::string& canvas,
2509 boost::shared_ptr<FramesCache> cache, 2512 boost::shared_ptr<FramesCache> cache,
2510 bool softwareRendering) : 2513 bool softwareRendering,
2514 bool linearInterpolation) :
2511 context_(context), 2515 context_(context),
2512 source_(source), 2516 source_(source),
2513 framesCache_(cache), 2517 framesCache_(cache),
2514 fitNextContent_(true), 2518 fitNextContent_(true),
2515 hasFocusOnInstance_(false), 2519 hasFocusOnInstance_(false),
2517 synchronizationOffset_(OrthancStone::LinearAlgebra::CreateVector(0, 0, 0)), 2521 synchronizationOffset_(OrthancStone::LinearAlgebra::CreateVector(0, 0, 0)),
2518 synchronizationEnabled_(false), 2522 synchronizationEnabled_(false),
2519 centralPhysicalWidth_(1), 2523 centralPhysicalWidth_(1),
2520 centralPhysicalHeight_(1), 2524 centralPhysicalHeight_(1),
2521 centralPixelSpacingX_(1), 2525 centralPixelSpacingX_(1),
2522 centralPixelSpacingY_(1) 2526 centralPixelSpacingY_(1),
2527 linearInterpolation_(linearInterpolation)
2523 { 2528 {
2524 if (!framesCache_) 2529 if (!framesCache_)
2525 { 2530 {
2526 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); 2531 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
2527 } 2532 }
2698 2703
2699 static boost::shared_ptr<ViewerViewport> Create(OrthancStone::WebAssemblyLoadersContext& context, 2704 static boost::shared_ptr<ViewerViewport> Create(OrthancStone::WebAssemblyLoadersContext& context,
2700 const OrthancStone::DicomSource& source, 2705 const OrthancStone::DicomSource& source,
2701 const std::string& canvas, 2706 const std::string& canvas,
2702 boost::shared_ptr<FramesCache> cache, 2707 boost::shared_ptr<FramesCache> cache,
2703 bool softwareRendering) 2708 bool softwareRendering,
2709 bool linearInterpolation)
2704 { 2710 {
2705 boost::shared_ptr<ViewerViewport> viewport( 2711 boost::shared_ptr<ViewerViewport> viewport(
2706 new ViewerViewport(context, source, canvas, cache, softwareRendering)); 2712 new ViewerViewport(context, source, canvas, cache, softwareRendering, linearInterpolation));
2707 2713
2708 { 2714 {
2709 std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(context.Lock()); 2715 std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(context.Lock());
2710 2716
2711 viewport->loader_ = OrthancStone::DicomResourcesLoader::Create(*lock); 2717 viewport->loader_ = OrthancStone::DicomResourcesLoader::Create(*lock);
3417 stoneAnnotations_->Render(lock->GetController().GetScene()); 3423 stoneAnnotations_->Render(lock->GetController().GetScene());
3418 lock->Invalidate(); 3424 lock->Invalidate();
3419 } 3425 }
3420 } 3426 }
3421 } 3427 }
3428 }
3429
3430 void SetLinearInterpolation(bool linearInterpolation)
3431 {
3432 if (linearInterpolation_ != linearInterpolation)
3433 {
3434 linearInterpolation_ = linearInterpolation;
3435 Redraw();
3436 }
3422 } 3437 }
3423 }; 3438 };
3424 3439
3425 3440
3426 3441
3687 static OrthancStone::DicomSource source_; 3702 static OrthancStone::DicomSource source_;
3688 static boost::shared_ptr<FramesCache> framesCache_; 3703 static boost::shared_ptr<FramesCache> framesCache_;
3689 static boost::shared_ptr<OrthancStone::WebAssemblyLoadersContext> context_; 3704 static boost::shared_ptr<OrthancStone::WebAssemblyLoadersContext> context_;
3690 static std::string stringBuffer_; 3705 static std::string stringBuffer_;
3691 static bool softwareRendering_ = false; 3706 static bool softwareRendering_ = false;
3707 static bool linearInterpolation_ = true;
3692 static WebViewerAction leftButtonAction_ = WebViewerAction_Windowing; 3708 static WebViewerAction leftButtonAction_ = WebViewerAction_Windowing;
3693 static WebViewerAction middleButtonAction_ = WebViewerAction_Pan; 3709 static WebViewerAction middleButtonAction_ = WebViewerAction_Pan;
3694 static WebViewerAction rightButtonAction_ = WebViewerAction_Zoom; 3710 static WebViewerAction rightButtonAction_ = WebViewerAction_Zoom;
3695 3711
3696 3712
3733 { 3749 {
3734 Viewports::iterator found = allViewports_.find(canvas); 3750 Viewports::iterator found = allViewports_.find(canvas);
3735 if (found == allViewports_.end()) 3751 if (found == allViewports_.end())
3736 { 3752 {
3737 boost::shared_ptr<ViewerViewport> viewport( 3753 boost::shared_ptr<ViewerViewport> viewport(
3738 ViewerViewport::Create(*context_, source_, canvas, framesCache_, softwareRendering_)); 3754 ViewerViewport::Create(*context_, source_, canvas, framesCache_, softwareRendering_, linearInterpolation_));
3739 viewport->SetMouseButtonActions(leftButtonAction_, middleButtonAction_, rightButtonAction_); 3755 viewport->SetMouseButtonActions(leftButtonAction_, middleButtonAction_, rightButtonAction_);
3740 viewport->AcquireObserver(new WebAssemblyObserver); 3756 viewport->AcquireObserver(new WebAssemblyObserver);
3741 viewport->SetOsiriXAnnotations(osiriXAnnotations_); 3757 viewport->SetOsiriXAnnotations(osiriXAnnotations_);
3742 allViewports_[canvas] = viewport; 3758 allViewports_[canvas] = viewport;
3743 return viewport; 3759 return viewport;
4252 return softwareRendering_; 4268 return softwareRendering_;
4253 } 4269 }
4254 4270
4255 4271
4256 EMSCRIPTEN_KEEPALIVE 4272 EMSCRIPTEN_KEEPALIVE
4273 void SetLinearInterpolation(int linearInterpolation)
4274 {
4275 linearInterpolation_ = linearInterpolation;
4276
4277 try
4278 {
4279 for (Viewports::iterator it = allViewports_.begin(); it != allViewports_.end(); ++it)
4280 {
4281 assert(it->second != NULL);
4282 it->second->SetLinearInterpolation(linearInterpolation);
4283 }
4284 }
4285 EXTERN_CATCH_EXCEPTIONS;
4286 }
4287
4288
4289 EMSCRIPTEN_KEEPALIVE
4257 void SetMouseButtonActions(int leftAction, 4290 void SetMouseButtonActions(int leftAction,
4258 int middleAction, 4291 int middleAction,
4259 int rightAction) 4292 int rightAction)
4260 { 4293 {
4261 try 4294 try