Mercurial > hg > orthanc-stone
comparison Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp @ 1989:e8b9a2ba1df1
Added left/right rotation buttons
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 31 Oct 2022 20:59:59 +0100 |
parents | ba45e1b0812a |
children | 317a53d4fdc6 |
comparison
equal
deleted
inserted
replaced
1988:3c84c34322d7 | 1989:e8b9a2ba1df1 |
---|---|
94 #include "../../../OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyCairoViewport.h" | 94 #include "../../../OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyCairoViewport.h" |
95 #include "../../../OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyLoadersContext.h" | 95 #include "../../../OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyLoadersContext.h" |
96 #include "../../../OrthancStone/Sources/Platforms/WebAssembly/WebGLViewport.h" | 96 #include "../../../OrthancStone/Sources/Platforms/WebAssembly/WebGLViewport.h" |
97 | 97 |
98 | 98 |
99 #include <algorithm> | |
100 #include <boost/make_shared.hpp> | |
101 #include <boost/math/constants/constants.hpp> | |
99 #include <boost/math/special_functions/round.hpp> | 102 #include <boost/math/special_functions/round.hpp> |
100 #include <boost/make_shared.hpp> | |
101 #include <stdio.h> | 103 #include <stdio.h> |
102 #include <algorithm> | 104 |
105 static const double PI = boost::math::constants::pi<double>(); | |
103 | 106 |
104 #if !defined(STONE_WEB_VIEWER_EXPORT) | 107 #if !defined(STONE_WEB_VIEWER_EXPORT) |
105 // We are not running ParseWebAssemblyExports.py, but we're compiling the wasm | 108 // We are not running ParseWebAssemblyExports.py, but we're compiling the wasm |
106 # define STONE_WEB_VIEWER_EXPORT | 109 # define STONE_WEB_VIEWER_EXPORT |
107 #endif | 110 #endif |
1991 float windowingWidth_; | 1994 float windowingWidth_; |
1992 std::vector<float> windowingPresetCenters_; | 1995 std::vector<float> windowingPresetCenters_; |
1993 std::vector<float> windowingPresetWidths_; | 1996 std::vector<float> windowingPresetWidths_; |
1994 unsigned int cineRate_; | 1997 unsigned int cineRate_; |
1995 bool inverted_; | 1998 bool inverted_; |
1996 bool flipX_; | |
1997 bool flipY_; | |
1998 bool fitNextContent_; | 1999 bool fitNextContent_; |
1999 std::list<PrefetchItem> prefetchQueue_; | 2000 std::list<PrefetchItem> prefetchQueue_; |
2000 bool serverSideTranscoding_; | 2001 bool serverSideTranscoding_; |
2001 OrthancStone::Vector synchronizationOffset_; | 2002 OrthancStone::Vector synchronizationOffset_; |
2002 bool synchronizationEnabled_; | 2003 bool synchronizationEnabled_; |
2153 } | 2154 } |
2154 | 2155 |
2155 assert(layer.get() != NULL); | 2156 assert(layer.get() != NULL); |
2156 | 2157 |
2157 layer->SetLinearInterpolation(true); | 2158 layer->SetLinearInterpolation(true); |
2158 layer->SetFlipX(flipX_); | |
2159 layer->SetFlipY(flipY_); | |
2160 | 2159 |
2161 double pixelSpacingX, pixelSpacingY; | 2160 double pixelSpacingX, pixelSpacingY; |
2162 | 2161 |
2163 if (instance.HasPixelSpacing()) | 2162 if (instance.HasPixelSpacing()) |
2164 { | 2163 { |
2208 { | 2207 { |
2209 OverlaysRegistry::Accessor accessor(OverlaysRegistry::GetInstance(), instance.GetSopInstanceUid()); | 2208 OverlaysRegistry::Accessor accessor(OverlaysRegistry::GetInstance(), instance.GetSopInstanceUid()); |
2210 if (accessor.IsValid()) | 2209 if (accessor.IsValid()) |
2211 { | 2210 { |
2212 overlay.reset(accessor.CreateTexture()); | 2211 overlay.reset(accessor.CreateTexture()); |
2213 overlay->SetFlipX(flipX_); | |
2214 overlay->SetFlipY(flipY_); | |
2215 } | 2212 } |
2216 } | 2213 } |
2217 | 2214 |
2218 std::unique_ptr<OrthancStone::MacroSceneLayer> annotationsOsiriX; | 2215 std::unique_ptr<OrthancStone::MacroSceneLayer> annotationsOsiriX; |
2219 | 2216 |
2494 { | 2491 { |
2495 dynamic_cast<OrthancStone::FloatTextureSceneLayer&>( | 2492 dynamic_cast<OrthancStone::FloatTextureSceneLayer&>( |
2496 lock->GetController().GetScene().GetLayer(LAYER_TEXTURE)). | 2493 lock->GetController().GetScene().GetLayer(LAYER_TEXTURE)). |
2497 SetCustomWindowing(windowingCenter_, windowingWidth_); | 2494 SetCustomWindowing(windowingCenter_, windowingWidth_); |
2498 } | 2495 } |
2499 | |
2500 { | |
2501 OrthancStone::TextureBaseSceneLayer& layer = | |
2502 dynamic_cast<OrthancStone::TextureBaseSceneLayer&>( | |
2503 lock->GetController().GetScene().GetLayer(LAYER_TEXTURE)); | |
2504 | |
2505 layer.SetFlipX(flipX_); | |
2506 layer.SetFlipY(flipY_); | |
2507 } | |
2508 | |
2509 if (lock->GetController().GetScene().HasLayer(LAYER_OVERLAY)) | |
2510 { | |
2511 OrthancStone::TextureBaseSceneLayer& layer = | |
2512 dynamic_cast<OrthancStone::TextureBaseSceneLayer&>( | |
2513 lock->GetController().GetScene().GetLayer(LAYER_OVERLAY)); | |
2514 | |
2515 layer.SetFlipX(flipX_); | |
2516 layer.SetFlipY(flipY_); | |
2517 } | |
2518 | 2496 |
2519 lock->Invalidate(); | 2497 lock->Invalidate(); |
2520 } | 2498 } |
2521 } | 2499 } |
2522 | 2500 |
2528 bool softwareRendering) : | 2506 bool softwareRendering) : |
2529 context_(context), | 2507 context_(context), |
2530 source_(source), | 2508 source_(source), |
2531 framesCache_(cache), | 2509 framesCache_(cache), |
2532 fitNextContent_(true), | 2510 fitNextContent_(true), |
2533 flipX_(false), | |
2534 flipY_(false), | |
2535 hasFocusOnInstance_(false), | 2511 hasFocusOnInstance_(false), |
2536 focusFrameNumber_(0), | 2512 focusFrameNumber_(0), |
2537 synchronizationOffset_(OrthancStone::LinearAlgebra::CreateVector(0, 0, 0)), | 2513 synchronizationOffset_(OrthancStone::LinearAlgebra::CreateVector(0, 0, 0)), |
2538 synchronizationEnabled_(false), | 2514 synchronizationEnabled_(false), |
2539 centralPhysicalWidth_(1), | 2515 centralPhysicalWidth_(1), |
2762 if (frames == NULL) | 2738 if (frames == NULL) |
2763 { | 2739 { |
2764 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | 2740 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
2765 } | 2741 } |
2766 | 2742 |
2767 flipX_ = false; | |
2768 flipY_ = false; | |
2769 fitNextContent_ = true; | 2743 fitNextContent_ = true; |
2770 cineRate_ = DEFAULT_CINE_RATE; | 2744 cineRate_ = DEFAULT_CINE_RATE; |
2771 inverted_ = false; | 2745 inverted_ = false; |
2772 serverSideTranscoding_ = false; | 2746 serverSideTranscoding_ = false; |
2773 OrthancStone::LinearAlgebra::AssignVector(synchronizationOffset_, 0, 0, 0); | 2747 OrthancStone::LinearAlgebra::AssignVector(synchronizationOffset_, 0, 0, 0); |
3095 } | 3069 } |
3096 } | 3070 } |
3097 | 3071 |
3098 void FlipX() | 3072 void FlipX() |
3099 { | 3073 { |
3100 flipX_ = !flipX_; | 3074 { |
3101 UpdateCurrentTextureParameters(); | 3075 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport_->Lock()); |
3076 lock->GetController().GetScene().FlipViewportX( | |
3077 lock->GetCompositor().GetCanvasWidth(), lock->GetCompositor().GetCanvasHeight()); | |
3078 lock->Invalidate(); | |
3079 } | |
3102 } | 3080 } |
3103 | 3081 |
3104 void FlipY() | 3082 void FlipY() |
3105 { | 3083 { |
3106 flipY_ = !flipY_; | 3084 { |
3107 UpdateCurrentTextureParameters(); | 3085 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport_->Lock()); |
3086 lock->GetController().GetScene().FlipViewportY( | |
3087 lock->GetCompositor().GetCanvasWidth(), lock->GetCompositor().GetCanvasHeight()); | |
3088 lock->Invalidate(); | |
3089 } | |
3090 } | |
3091 | |
3092 void RotateLeft() | |
3093 { | |
3094 { | |
3095 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport_->Lock()); | |
3096 lock->GetController().GetScene().RotateViewport( | |
3097 -PI / 2.0, lock->GetCompositor().GetCanvasWidth(), lock->GetCompositor().GetCanvasHeight()); | |
3098 lock->Invalidate(); | |
3099 } | |
3100 } | |
3101 | |
3102 void RotateRight() | |
3103 { | |
3104 { | |
3105 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport_->Lock()); | |
3106 lock->GetController().GetScene().RotateViewport( | |
3107 PI / 2.0, lock->GetCompositor().GetCanvasWidth(), lock->GetCompositor().GetCanvasHeight()); | |
3108 lock->Invalidate(); | |
3109 } | |
3108 } | 3110 } |
3109 | 3111 |
3110 void Invert() | 3112 void Invert() |
3111 { | 3113 { |
3112 inverted_ = !inverted_; | 3114 inverted_ = !inverted_; |
4210 EXTERN_CATCH_EXCEPTIONS; | 4212 EXTERN_CATCH_EXCEPTIONS; |
4211 } | 4213 } |
4212 | 4214 |
4213 | 4215 |
4214 EMSCRIPTEN_KEEPALIVE | 4216 EMSCRIPTEN_KEEPALIVE |
4217 void RotateLeft(const char* canvas) | |
4218 { | |
4219 try | |
4220 { | |
4221 GetViewport(canvas)->RotateLeft(); | |
4222 } | |
4223 EXTERN_CATCH_EXCEPTIONS; | |
4224 } | |
4225 | |
4226 | |
4227 EMSCRIPTEN_KEEPALIVE | |
4228 void RotateRight(const char* canvas) | |
4229 { | |
4230 try | |
4231 { | |
4232 GetViewport(canvas)->RotateRight(); | |
4233 } | |
4234 EXTERN_CATCH_EXCEPTIONS; | |
4235 } | |
4236 | |
4237 | |
4238 EMSCRIPTEN_KEEPALIVE | |
4215 void SetSoftwareRendering(int softwareRendering) | 4239 void SetSoftwareRendering(int softwareRendering) |
4216 { | 4240 { |
4217 softwareRendering_ = softwareRendering; | 4241 softwareRendering_ = softwareRendering; |
4218 } | 4242 } |
4219 | 4243 |