Mercurial > hg > orthanc-stone
comparison Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp @ 1554:6d14ed6163b1
flip x/y in Stone Web viewer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 17 Aug 2020 16:10:00 +0200 |
parents | a4d82f1bcb10 |
children | 314b6dc507d9 |
comparison
equal
deleted
inserted
replaced
1553:bf02a90ca9ca | 1554:6d14ed6163b1 |
---|---|
1232 float windowingCenter_; | 1232 float windowingCenter_; |
1233 float windowingWidth_; | 1233 float windowingWidth_; |
1234 float defaultWindowingCenter_; | 1234 float defaultWindowingCenter_; |
1235 float defaultWindowingWidth_; | 1235 float defaultWindowingWidth_; |
1236 bool inverted_; | 1236 bool inverted_; |
1237 bool flipX_; | |
1238 bool flipY_; | |
1237 bool fitNextContent_; | 1239 bool fitNextContent_; |
1238 bool isCtrlDown_; | 1240 bool isCtrlDown_; |
1239 FrameGeometry currentFrameGeometry_; | 1241 FrameGeometry currentFrameGeometry_; |
1240 std::list<PrefetchItem> prefetchQueue_; | 1242 std::list<PrefetchItem> prefetchQueue_; |
1241 | 1243 |
1423 default: | 1425 default: |
1424 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); | 1426 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
1425 } | 1427 } |
1426 | 1428 |
1427 layer->SetLinearInterpolation(true); | 1429 layer->SetLinearInterpolation(true); |
1430 layer->SetFlipX(flipX_); | |
1431 layer->SetFlipY(flipY_); | |
1428 | 1432 |
1429 double pixelSpacingX, pixelSpacingY; | 1433 double pixelSpacingX, pixelSpacingY; |
1430 OrthancStone::GeometryToolbox::GetPixelSpacing( | 1434 OrthancStone::GeometryToolbox::GetPixelSpacing( |
1431 pixelSpacingX, pixelSpacingY, frames_->GetFrameTags(index)); | 1435 pixelSpacingX, pixelSpacingY, frames_->GetFrameTags(index)); |
1432 layer->SetPixelSpacing(pixelSpacingX, pixelSpacingY); | 1436 layer->SetPixelSpacing(pixelSpacingX, pixelSpacingY); |
1517 lock->Schedule(GetSharedObserver(), priority, command.release()); | 1521 lock->Schedule(GetSharedObserver(), priority, command.release()); |
1518 } | 1522 } |
1519 } | 1523 } |
1520 } | 1524 } |
1521 | 1525 |
1526 void UpdateCurrentTextureParameters() | |
1527 { | |
1528 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport_->Lock()); | |
1529 | |
1530 if (lock->GetController().GetScene().HasLayer(LAYER_TEXTURE)) | |
1531 { | |
1532 if (lock->GetController().GetScene().GetLayer(LAYER_TEXTURE).GetType() == | |
1533 OrthancStone::ISceneLayer::Type_FloatTexture) | |
1534 { | |
1535 dynamic_cast<OrthancStone::FloatTextureSceneLayer&>( | |
1536 lock->GetController().GetScene().GetLayer(LAYER_TEXTURE)). | |
1537 SetCustomWindowing(windowingCenter_, windowingWidth_); | |
1538 } | |
1539 | |
1540 { | |
1541 OrthancStone::TextureBaseSceneLayer& layer = | |
1542 dynamic_cast<OrthancStone::TextureBaseSceneLayer&>( | |
1543 lock->GetController().GetScene().GetLayer(LAYER_TEXTURE)); | |
1544 | |
1545 layer.SetFlipX(flipX_); | |
1546 layer.SetFlipY(flipY_); | |
1547 } | |
1548 | |
1549 lock->Invalidate(); | |
1550 } | |
1551 } | |
1552 | |
1553 | |
1522 ViewerViewport(OrthancStone::ILoadersContext& context, | 1554 ViewerViewport(OrthancStone::ILoadersContext& context, |
1523 const OrthancStone::DicomSource& source, | 1555 const OrthancStone::DicomSource& source, |
1524 const std::string& canvas, | 1556 const std::string& canvas, |
1525 boost::shared_ptr<FramesCache> cache, | 1557 boost::shared_ptr<FramesCache> cache, |
1526 bool softwareRendering) : | 1558 bool softwareRendering) : |
1527 context_(context), | 1559 context_(context), |
1528 source_(source), | 1560 source_(source), |
1529 cache_(cache), | 1561 cache_(cache), |
1530 fitNextContent_(true), | 1562 fitNextContent_(true), |
1531 isCtrlDown_(false) | 1563 isCtrlDown_(false), |
1564 flipX_(false), | |
1565 flipY_(false) | |
1532 { | 1566 { |
1533 if (!cache_) | 1567 if (!cache_) |
1534 { | 1568 { |
1535 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | 1569 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
1536 } | 1570 } |
1549 emscripten_set_wheel_callback(viewport_->GetCanvasCssSelector().c_str(), this, true, OnWheel); | 1583 emscripten_set_wheel_callback(viewport_->GetCanvasCssSelector().c_str(), this, true, OnWheel); |
1550 emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, OnKey); | 1584 emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, OnKey); |
1551 emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, OnKey); | 1585 emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, OnKey); |
1552 | 1586 |
1553 ResetDefaultWindowing(); | 1587 ResetDefaultWindowing(); |
1588 | |
1589 /*{ | |
1590 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport_->Lock()); | |
1591 std::unique_ptr<OrthancStone::PolylineSceneLayer> layer(new OrthancStone::PolylineSceneLayer); | |
1592 OrthancStone::PolylineSceneLayer::Chain chain; | |
1593 chain.push_back(OrthancStone::ScenePoint2D(-10, 0)); | |
1594 chain.push_back(OrthancStone::ScenePoint2D(10, 0)); | |
1595 layer->AddChain(chain, false, 255, 0, 0); | |
1596 chain.clear(); | |
1597 chain.push_back(OrthancStone::ScenePoint2D(0, -10)); | |
1598 chain.push_back(OrthancStone::ScenePoint2D(0, 10)); | |
1599 layer->AddChain(chain, false, 255, 0, 0); | |
1600 chain.clear(); | |
1601 chain.push_back(OrthancStone::ScenePoint2D(40, 30)); | |
1602 chain.push_back(OrthancStone::ScenePoint2D(40, 50)); | |
1603 layer->AddChain(chain, false, 255, 0, 0); | |
1604 chain.clear(); | |
1605 chain.push_back(OrthancStone::ScenePoint2D(30, 40)); | |
1606 chain.push_back(OrthancStone::ScenePoint2D(50, 40)); | |
1607 layer->AddChain(chain, false, 255, 0, 0); | |
1608 lock->GetController().GetScene().SetLayer(1000, layer.release()); | |
1609 lock->Invalidate(); | |
1610 }*/ | |
1554 } | 1611 } |
1555 | 1612 |
1556 static EM_BOOL OnKey(int eventType, | 1613 static EM_BOOL OnKey(int eventType, |
1557 const EmscriptenKeyboardEvent *event, | 1614 const EmscriptenKeyboardEvent *event, |
1558 void *userData) | 1615 void *userData) |
1632 if (frames == NULL) | 1689 if (frames == NULL) |
1633 { | 1690 { |
1634 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | 1691 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
1635 } | 1692 } |
1636 | 1693 |
1694 flipX_ = false; | |
1695 flipY_ = false; | |
1637 fitNextContent_ = true; | 1696 fitNextContent_ = true; |
1638 | 1697 |
1639 frames_.reset(frames); | 1698 frames_.reset(frames); |
1640 cursor_.reset(new SeriesCursor(frames_->GetFramesCount())); | 1699 cursor_.reset(new SeriesCursor(frames_->GetFramesCount())); |
1641 | 1700 |
1774 void SetWindowing(float windowingCenter, | 1833 void SetWindowing(float windowingCenter, |
1775 float windowingWidth) | 1834 float windowingWidth) |
1776 { | 1835 { |
1777 windowingCenter_ = windowingCenter; | 1836 windowingCenter_ = windowingCenter; |
1778 windowingWidth_ = windowingWidth; | 1837 windowingWidth_ = windowingWidth; |
1779 | 1838 UpdateCurrentTextureParameters(); |
1780 { | 1839 } |
1781 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport_->Lock()); | 1840 |
1782 | 1841 void FlipX() |
1783 if (lock->GetController().GetScene().HasLayer(LAYER_TEXTURE) && | 1842 { |
1784 lock->GetController().GetScene().GetLayer(LAYER_TEXTURE).GetType() == | 1843 flipX_ = !flipX_; |
1785 OrthancStone::ISceneLayer::Type_FloatTexture) | 1844 UpdateCurrentTextureParameters(); |
1786 { | 1845 } |
1787 dynamic_cast<OrthancStone::FloatTextureSceneLayer&>( | 1846 |
1788 lock->GetController().GetScene().GetLayer(LAYER_TEXTURE)). | 1847 void FlipY() |
1789 SetCustomWindowing(windowingCenter_, windowingWidth_); | 1848 { |
1790 lock->Invalidate(); | 1849 flipY_ = !flipY_; |
1791 } | 1850 UpdateCurrentTextureParameters(); |
1792 } | |
1793 } | 1851 } |
1794 | 1852 |
1795 void Invert() | 1853 void Invert() |
1796 { | 1854 { |
1797 inverted_ = !inverted_; | 1855 inverted_ = !inverted_; |
2283 EXTERN_CATCH_EXCEPTIONS; | 2341 EXTERN_CATCH_EXCEPTIONS; |
2284 } | 2342 } |
2285 | 2343 |
2286 | 2344 |
2287 EMSCRIPTEN_KEEPALIVE | 2345 EMSCRIPTEN_KEEPALIVE |
2346 void FlipX(const char* canvas) | |
2347 { | |
2348 try | |
2349 { | |
2350 GetViewport(canvas)->FlipX(); | |
2351 } | |
2352 EXTERN_CATCH_EXCEPTIONS; | |
2353 } | |
2354 | |
2355 | |
2356 EMSCRIPTEN_KEEPALIVE | |
2357 void FlipY(const char* canvas) | |
2358 { | |
2359 try | |
2360 { | |
2361 GetViewport(canvas)->FlipY(); | |
2362 } | |
2363 EXTERN_CATCH_EXCEPTIONS; | |
2364 } | |
2365 | |
2366 | |
2367 EMSCRIPTEN_KEEPALIVE | |
2288 void SetSoftwareRendering(int softwareRendering) | 2368 void SetSoftwareRendering(int softwareRendering) |
2289 { | 2369 { |
2290 softwareRendering_ = softwareRendering; | 2370 softwareRendering_ = softwareRendering; |
2291 } | 2371 } |
2292 | 2372 |