Mercurial > hg > orthanc-stone
changeset 414:f7616c010056
reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 12 Nov 2018 18:00:48 +0100 |
parents | 18b707fb8620 |
children | c0589c3173fd |
files | Applications/Samples/SingleFrameEditorApplication.h Framework/Radiography/RadiographyLayerMoveTracker.cpp Framework/Radiography/RadiographyLayerMoveTracker.h Framework/Radiography/RadiographyLayerRotateTracker.cpp Framework/Radiography/RadiographyLayerRotateTracker.h Resources/CMake/OrthancStoneConfiguration.cmake |
diffstat | 6 files changed, 424 insertions(+), 297 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Samples/SingleFrameEditorApplication.h Mon Nov 12 17:17:25 2018 +0100 +++ b/Applications/Samples/SingleFrameEditorApplication.h Mon Nov 12 18:00:48 2018 +0100 @@ -23,7 +23,10 @@ #include "SampleApplicationBase.h" +#include "../../Framework/Radiography/RadiographyLayerMoveTracker.h" +#include "../../Framework/Radiography/RadiographyLayerRotateTracker.h" #include "../../Framework/Radiography/RadiographyScene.h" +#include "../../Framework/Radiography/RadiographySceneCommand.h" #include "../../Framework/Radiography/RadiographyWidget.h" #include "../../Framework/Toolbox/UndoRedoStack.h" @@ -46,308 +49,11 @@ #define EXPORT_USING_PAM 1 -#include <boost/math/constants/constants.hpp> #include <boost/math/special_functions/round.hpp> namespace OrthancStone { - class RadiographySceneCommand : public UndoRedoStack::ICommand - { - private: - RadiographyScene& scene_; - size_t layer_; - - protected: - virtual void UndoInternal(RadiographyLayer& layer) const = 0; - - virtual void RedoInternal(RadiographyLayer& layer) const = 0; - - public: - RadiographySceneCommand(RadiographyScene& scene, - size_t layer) : - scene_(scene), - layer_(layer) - { - } - - RadiographySceneCommand(const RadiographyScene::LayerAccessor& accessor) : - scene_(accessor.GetScene()), - layer_(accessor.GetIndex()) - { - } - - virtual void Undo() const - { - RadiographyScene::LayerAccessor accessor(scene_, layer_); - - if (accessor.IsValid()) - { - UndoInternal(accessor.GetLayer()); - } - } - - virtual void Redo() const - { - RadiographyScene::LayerAccessor accessor(scene_, layer_); - - if (accessor.IsValid()) - { - RedoInternal(accessor.GetLayer()); - } - } - }; - - - class RadiographyLayerRotateTracker : public IWorldSceneMouseTracker - { - private: - UndoRedoStack& undoRedoStack_; - RadiographyScene::LayerAccessor accessor_; - double centerX_; - double centerY_; - double originalAngle_; - double clickAngle_; - bool roundAngles_; - - bool ComputeAngle(double& angle /* out */, - double sceneX, - double sceneY) const - { - Vector u; - LinearAlgebra::AssignVector(u, sceneX - centerX_, sceneY - centerY_); - - double nu = boost::numeric::ublas::norm_2(u); - - if (!LinearAlgebra::IsCloseToZero(nu)) - { - u /= nu; - angle = atan2(u[1], u[0]); - return true; - } - else - { - return false; - } - } - - - class UndoRedoCommand : public RadiographySceneCommand - { - private: - double sourceAngle_; - double targetAngle_; - - static int ToDegrees(double angle) - { - return boost::math::iround(angle * 180.0 / boost::math::constants::pi<double>()); - } - - protected: - virtual void UndoInternal(RadiographyLayer& layer) const - { - LOG(INFO) << "Undo - Set angle to " << ToDegrees(sourceAngle_) << " degrees"; - layer.SetAngle(sourceAngle_); - } - - virtual void RedoInternal(RadiographyLayer& layer) const - { - LOG(INFO) << "Redo - Set angle to " << ToDegrees(sourceAngle_) << " degrees"; - layer.SetAngle(targetAngle_); - } - - public: - UndoRedoCommand(const RadiographyLayerRotateTracker& tracker) : - RadiographySceneCommand(tracker.accessor_), - sourceAngle_(tracker.originalAngle_), - targetAngle_(tracker.accessor_.GetLayer().GetAngle()) - { - } - }; - - - public: - RadiographyLayerRotateTracker(UndoRedoStack& undoRedoStack, - RadiographyScene& scene, - const ViewportGeometry& view, - size_t layer, - double x, - double y, - bool roundAngles) : - undoRedoStack_(undoRedoStack), - accessor_(scene, layer), - roundAngles_(roundAngles) - { - if (accessor_.IsValid()) - { - accessor_.GetLayer().GetCenter(centerX_, centerY_); - originalAngle_ = accessor_.GetLayer().GetAngle(); - - double sceneX, sceneY; - view.MapDisplayToScene(sceneX, sceneY, x, y); - - if (!ComputeAngle(clickAngle_, x, y)) - { - accessor_.Invalidate(); - } - } - } - - virtual bool HasRender() const - { - return false; - } - - virtual void Render(CairoContext& context, - double zoom) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); - } - - virtual void MouseUp() - { - if (accessor_.IsValid()) - { - undoRedoStack_.Add(new UndoRedoCommand(*this)); - } - } - - virtual void MouseMove(int displayX, - int displayY, - double sceneX, - double sceneY) - { - static const double ROUND_ANGLE = 15.0 / 180.0 * boost::math::constants::pi<double>(); - - double angle; - - if (accessor_.IsValid() && - ComputeAngle(angle, sceneX, sceneY)) - { - angle = angle - clickAngle_ + originalAngle_; - - if (roundAngles_) - { - angle = boost::math::round<double>((angle / ROUND_ANGLE) * ROUND_ANGLE); - } - - accessor_.GetLayer().SetAngle(angle); - } - } - }; - - - class RadiographyLayerMoveTracker : public IWorldSceneMouseTracker - { - private: - UndoRedoStack& undoRedoStack_; - RadiographyScene::LayerAccessor accessor_; - double clickX_; - double clickY_; - double panX_; - double panY_; - bool oneAxis_; - - class UndoRedoCommand : public RadiographySceneCommand - { - private: - double sourceX_; - double sourceY_; - double targetX_; - double targetY_; - - protected: - virtual void UndoInternal(RadiographyLayer& layer) const - { - layer.SetPan(sourceX_, sourceY_); - } - - virtual void RedoInternal(RadiographyLayer& layer) const - { - layer.SetPan(targetX_, targetY_); - } - - public: - UndoRedoCommand(const RadiographyLayerMoveTracker& tracker) : - RadiographySceneCommand(tracker.accessor_), - sourceX_(tracker.panX_), - sourceY_(tracker.panY_), - targetX_(tracker.accessor_.GetLayer().GetPanX()), - targetY_(tracker.accessor_.GetLayer().GetPanY()) - { - } - }; - - - public: - RadiographyLayerMoveTracker(UndoRedoStack& undoRedoStack, - RadiographyScene& scene, - size_t layer, - double x, - double y, - bool oneAxis) : - undoRedoStack_(undoRedoStack), - accessor_(scene, layer), - clickX_(x), - clickY_(y), - oneAxis_(oneAxis) - { - if (accessor_.IsValid()) - { - panX_ = accessor_.GetLayer().GetPanX(); - panY_ = accessor_.GetLayer().GetPanY(); - } - } - - virtual bool HasRender() const - { - return false; - } - - virtual void Render(CairoContext& context, - double zoom) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); - } - - virtual void MouseUp() - { - if (accessor_.IsValid()) - { - undoRedoStack_.Add(new UndoRedoCommand(*this)); - } - } - - virtual void MouseMove(int displayX, - int displayY, - double sceneX, - double sceneY) - { - if (accessor_.IsValid()) - { - double dx = sceneX - clickX_; - double dy = sceneY - clickY_; - - if (oneAxis_) - { - if (fabs(dx) > fabs(dy)) - { - accessor_.GetLayer().SetPan(dx + panX_, panY_); - } - else - { - accessor_.GetLayer().SetPan(panX_, dy + panY_); - } - } - else - { - accessor_.GetLayer().SetPan(dx + panX_, dy + panY_); - } - } - } - }; - - class RadiographyLayerCropTracker : public IWorldSceneMouseTracker { private:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Radiography/RadiographyLayerMoveTracker.cpp Mon Nov 12 18:00:48 2018 +0100 @@ -0,0 +1,124 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2018 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "RadiographyLayerMoveTracker.h" + +#include "RadiographySceneCommand.h" + +#include <Core/OrthancException.h> + +namespace OrthancStone +{ + class RadiographyLayerMoveTracker::UndoRedoCommand : public RadiographySceneCommand + { + private: + double sourceX_; + double sourceY_; + double targetX_; + double targetY_; + + protected: + virtual void UndoInternal(RadiographyLayer& layer) const + { + layer.SetPan(sourceX_, sourceY_); + } + + virtual void RedoInternal(RadiographyLayer& layer) const + { + layer.SetPan(targetX_, targetY_); + } + + public: + UndoRedoCommand(const RadiographyLayerMoveTracker& tracker) : + RadiographySceneCommand(tracker.accessor_), + sourceX_(tracker.panX_), + sourceY_(tracker.panY_), + targetX_(tracker.accessor_.GetLayer().GetPanX()), + targetY_(tracker.accessor_.GetLayer().GetPanY()) + { + } + }; + + + RadiographyLayerMoveTracker::RadiographyLayerMoveTracker(UndoRedoStack& undoRedoStack, + RadiographyScene& scene, + size_t layer, + double x, + double y, + bool oneAxis) : + undoRedoStack_(undoRedoStack), + accessor_(scene, layer), + clickX_(x), + clickY_(y), + oneAxis_(oneAxis) + { + if (accessor_.IsValid()) + { + panX_ = accessor_.GetLayer().GetPanX(); + panY_ = accessor_.GetLayer().GetPanY(); + } + } + + + void RadiographyLayerMoveTracker::Render(CairoContext& context, + double zoom) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + + + void RadiographyLayerMoveTracker::MouseUp() + { + if (accessor_.IsValid()) + { + undoRedoStack_.Add(new UndoRedoCommand(*this)); + } + } + + + void RadiographyLayerMoveTracker::MouseMove(int displayX, + int displayY, + double sceneX, + double sceneY) + { + if (accessor_.IsValid()) + { + double dx = sceneX - clickX_; + double dy = sceneY - clickY_; + + if (oneAxis_) + { + if (fabs(dx) > fabs(dy)) + { + accessor_.GetLayer().SetPan(dx + panX_, panY_); + } + else + { + accessor_.GetLayer().SetPan(panX_, dy + panY_); + } + } + else + { + accessor_.GetLayer().SetPan(dx + panX_, dy + panY_); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Radiography/RadiographyLayerMoveTracker.h Mon Nov 12 18:00:48 2018 +0100 @@ -0,0 +1,66 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2018 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "../Toolbox/UndoRedoStack.h" +#include "../Widgets/IWorldSceneMouseTracker.h" +#include "RadiographyScene.h" + +namespace OrthancStone +{ + class RadiographyLayerMoveTracker : public IWorldSceneMouseTracker + { + private: + class UndoRedoCommand; + + UndoRedoStack& undoRedoStack_; + RadiographyScene::LayerAccessor accessor_; + double clickX_; + double clickY_; + double panX_; + double panY_; + bool oneAxis_; + + public: + RadiographyLayerMoveTracker(UndoRedoStack& undoRedoStack, + RadiographyScene& scene, + size_t layer, + double x, + double y, + bool oneAxis); + + virtual bool HasRender() const + { + return false; + } + + virtual void Render(CairoContext& context, + double zoom); + + virtual void MouseUp(); + + virtual void MouseMove(int displayX, + int displayY, + double sceneX, + double sceneY); + }; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Radiography/RadiographyLayerRotateTracker.cpp Mon Nov 12 18:00:48 2018 +0100 @@ -0,0 +1,154 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2018 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "RadiographyLayerRotateTracker.h" + +#include "RadiographySceneCommand.h" + +#include <Core/OrthancException.h> + +#include <boost/math/constants/constants.hpp> +#include <boost/math/special_functions/round.hpp> + +namespace OrthancStone +{ + class RadiographyLayerRotateTracker::UndoRedoCommand : public RadiographySceneCommand + { + private: + double sourceAngle_; + double targetAngle_; + + static int ToDegrees(double angle) + { + return boost::math::iround(angle * 180.0 / boost::math::constants::pi<double>()); + } + + protected: + virtual void UndoInternal(RadiographyLayer& layer) const + { + LOG(INFO) << "Undo - Set angle to " << ToDegrees(sourceAngle_) << " degrees"; + layer.SetAngle(sourceAngle_); + } + + virtual void RedoInternal(RadiographyLayer& layer) const + { + LOG(INFO) << "Redo - Set angle to " << ToDegrees(sourceAngle_) << " degrees"; + layer.SetAngle(targetAngle_); + } + + public: + UndoRedoCommand(const RadiographyLayerRotateTracker& tracker) : + RadiographySceneCommand(tracker.accessor_), + sourceAngle_(tracker.originalAngle_), + targetAngle_(tracker.accessor_.GetLayer().GetAngle()) + { + } + }; + + + bool RadiographyLayerRotateTracker::ComputeAngle(double& angle /* out */, + double sceneX, + double sceneY) const + { + Vector u; + LinearAlgebra::AssignVector(u, sceneX - centerX_, sceneY - centerY_); + + double nu = boost::numeric::ublas::norm_2(u); + + if (!LinearAlgebra::IsCloseToZero(nu)) + { + u /= nu; + angle = atan2(u[1], u[0]); + return true; + } + else + { + return false; + } + } + + + RadiographyLayerRotateTracker::RadiographyLayerRotateTracker(UndoRedoStack& undoRedoStack, + RadiographyScene& scene, + const ViewportGeometry& view, + size_t layer, + double x, + double y, + bool roundAngles) : + undoRedoStack_(undoRedoStack), + accessor_(scene, layer), + roundAngles_(roundAngles) + { + if (accessor_.IsValid()) + { + accessor_.GetLayer().GetCenter(centerX_, centerY_); + originalAngle_ = accessor_.GetLayer().GetAngle(); + + double sceneX, sceneY; + view.MapDisplayToScene(sceneX, sceneY, x, y); + + if (!ComputeAngle(clickAngle_, x, y)) + { + accessor_.Invalidate(); + } + } + } + + + void RadiographyLayerRotateTracker::Render(CairoContext& context, + double zoom) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + + + void RadiographyLayerRotateTracker::MouseUp() + { + if (accessor_.IsValid()) + { + undoRedoStack_.Add(new UndoRedoCommand(*this)); + } + } + + + void RadiographyLayerRotateTracker::MouseMove(int displayX, + int displayY, + double sceneX, + double sceneY) + { + static const double ROUND_ANGLE = 15.0 / 180.0 * boost::math::constants::pi<double>(); + + double angle; + + if (accessor_.IsValid() && + ComputeAngle(angle, sceneX, sceneY)) + { + angle = angle - clickAngle_ + originalAngle_; + + if (roundAngles_) + { + angle = boost::math::round<double>((angle / ROUND_ANGLE) * ROUND_ANGLE); + } + + accessor_.GetLayer().SetAngle(angle); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Radiography/RadiographyLayerRotateTracker.h Mon Nov 12 18:00:48 2018 +0100 @@ -0,0 +1,73 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2018 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "../Toolbox/UndoRedoStack.h" +#include "../Toolbox/ViewportGeometry.h" +#include "../Widgets/IWorldSceneMouseTracker.h" +#include "RadiographyScene.h" + + +namespace OrthancStone +{ + class RadiographyLayerRotateTracker : public IWorldSceneMouseTracker + { + private: + class UndoRedoCommand; + + UndoRedoStack& undoRedoStack_; + RadiographyScene::LayerAccessor accessor_; + double centerX_; + double centerY_; + double originalAngle_; + double clickAngle_; + bool roundAngles_; + + bool ComputeAngle(double& angle /* out */, + double sceneX, + double sceneY) const; + + public: + RadiographyLayerRotateTracker(UndoRedoStack& undoRedoStack, + RadiographyScene& scene, + const ViewportGeometry& view, + size_t layer, + double x, + double y, + bool roundAngles); + + virtual bool HasRender() const + { + return false; + } + + virtual void Render(CairoContext& context, + double zoom); + + virtual void MouseUp(); + + virtual void MouseMove(int displayX, + int displayY, + double sceneX, + double sceneY); + }; +}
--- a/Resources/CMake/OrthancStoneConfiguration.cmake Mon Nov 12 17:17:25 2018 +0100 +++ b/Resources/CMake/OrthancStoneConfiguration.cmake Mon Nov 12 18:00:48 2018 +0100 @@ -246,6 +246,8 @@ ${ORTHANC_STONE_ROOT}/Framework/Layers/LineMeasureTracker.cpp ${ORTHANC_STONE_ROOT}/Framework/Layers/RenderStyle.cpp ${ORTHANC_STONE_ROOT}/Framework/Layers/SliceOutlineRenderer.cpp + ${ORTHANC_STONE_ROOT}/Framework/Radiography/RadiographyLayerMoveTracker.cpp + ${ORTHANC_STONE_ROOT}/Framework/Radiography/RadiographyLayerRotateTracker.cpp ${ORTHANC_STONE_ROOT}/Framework/Radiography/RadiographyLayer.cpp ${ORTHANC_STONE_ROOT}/Framework/Radiography/RadiographyScene.cpp ${ORTHANC_STONE_ROOT}/Framework/Radiography/RadiographySceneCommand.cpp @@ -350,6 +352,8 @@ NOT IS_DIRECTORY ${_header} AND NOT IS_SYMLINK ${_header}) + # Prevent adding the header twice if it is already manually + # specified in the sources list (FIND SOURCES_VAR ${_header} _index) if (${_index} EQUAL -1) list(APPEND TMP ${_header})