# HG changeset patch # User Sebastien Jodogne # Date 1555684988 -7200 # Node ID e36e69a380a59e1171c813213212375159297fc9 # Parent d933fc19214a94be6e144b44b63250c999b4798f Scene2D diff -r d933fc19214a -r e36e69a380a5 Framework/OpenGL/OpenGLIncludes.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/OpenGL/OpenGLIncludes.h Fri Apr 19 16:43:08 2019 +0200 @@ -0,0 +1,41 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 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 . + **/ + + +#pragma once + +#if !defined(ORTHANC_ENABLE_OPENGL) +# error The macro ORTHANC_ENABLE_OPENGL must be defined +#endif + +#if ORTHANC_ENABLE_OPENGL != 1 +# error Support for OpenGL is disabled +#endif + +#if defined(__APPLE__) +# include +# include +#else +# if defined(_WIN32) +# include +# endif +# include +# include +#endif diff -r d933fc19214a -r e36e69a380a5 Framework/OpenGL/OpenGLProgram.h --- a/Framework/OpenGL/OpenGLProgram.h Fri Apr 19 16:17:13 2019 +0200 +++ b/Framework/OpenGL/OpenGLProgram.h Fri Apr 19 16:43:08 2019 +0200 @@ -21,21 +21,7 @@ #pragma once -#if !defined(ORTHANC_ENABLE_OPENGL) -# error The macro ORTHANC_ENABLE_OPENGL must be defined -#endif - -#if ORTHANC_ENABLE_OPENGL != 1 -# error Support for OpenGL is disabled -#endif - -#if defined(__APPLE__) -# include -# include -#else -# include -# include -#endif +#include "OpenGLIncludes.h" #include #include diff -r d933fc19214a -r e36e69a380a5 Framework/OpenGL/OpenGLShader.h --- a/Framework/OpenGL/OpenGLShader.h Fri Apr 19 16:17:13 2019 +0200 +++ b/Framework/OpenGL/OpenGLShader.h Fri Apr 19 16:43:08 2019 +0200 @@ -21,21 +21,7 @@ #pragma once -#if !defined(ORTHANC_ENABLE_OPENGL) -# error The macro ORTHANC_ENABLE_OPENGL must be defined -#endif - -#if ORTHANC_ENABLE_OPENGL != 1 -# error Support for OpenGL is disabled -#endif - -#if defined(__APPLE__) -# include -# include -#else -# include -# include -#endif +#include "OpenGLIncludes.h" #include #include diff -r d933fc19214a -r e36e69a380a5 Framework/OpenGL/OpenGLTexture.h --- a/Framework/OpenGL/OpenGLTexture.h Fri Apr 19 16:17:13 2019 +0200 +++ b/Framework/OpenGL/OpenGLTexture.h Fri Apr 19 16:43:08 2019 +0200 @@ -21,21 +21,7 @@ #pragma once -#if !defined(ORTHANC_ENABLE_OPENGL) -# error The macro ORTHANC_ENABLE_OPENGL must be defined -#endif - -#if ORTHANC_ENABLE_OPENGL != 1 -# error Support for OpenGL is disabled -#endif - -#if defined(__APPLE__) -# include -# include -#else -# include -# include -#endif +#include "OpenGLIncludes.h" #include diff -r d933fc19214a -r e36e69a380a5 Framework/Scene2D/ISceneLayer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/ISceneLayer.h Fri Apr 19 16:43:08 2019 +0200 @@ -0,0 +1,54 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 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 . + **/ + + +#pragma once + +#include "../Toolbox/Extent2D.h" + +#include +#include + +namespace OrthancStone +{ + class ISceneLayer : public boost::noncopyable + { + public: + enum Type + { + Type_InfoPanel, + Type_Texture, + Type_Polyline, + Type_Text + }; + + virtual ~ISceneLayer() + { + } + + virtual ISceneLayer* Clone() const = 0; + + virtual Type GetType() const = 0; + + virtual bool GetBoundingBox(Extent2D& target) const = 0; + + virtual uint64_t GetRevision() const = 0; + }; +} diff -r d933fc19214a -r e36e69a380a5 Framework/Scene2D/Scene2D.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Scene2D.cpp Fri Apr 19 16:43:08 2019 +0200 @@ -0,0 +1,151 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 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 . + **/ + + +#include "Scene2D.h" + +#include + + +namespace OrthancStone +{ + Scene2D::Scene2D(const Scene2D& other) : + sceneToCanvas_(other.sceneToCanvas_), + canvasToScene_(other.canvasToScene_) + { + for (Content::const_iterator it = other.content_.begin(); + it != other.content_.end(); ++it) + { + content_[it->first] = it->second->Clone(); + } + } + + + Scene2D::~Scene2D() + { + for (Content::iterator it = content_.begin(); + it != content_.end(); ++it) + { + assert(it->second != NULL); + delete it->second; + } + } + + + void Scene2D::SetLayer(int depth, + ISceneLayer* layer) // Takes ownership + { + std::auto_ptr protection(layer); + + if (layer == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); + } + + Content::iterator found = content_.find(depth); + + if (found == content_.end()) + { + content_[depth] = protection.release(); + } + else + { + assert(found->second != NULL); + delete found->second; + found->second = protection.release(); + } + } + + + void Scene2D::DeleteLayer(int depth) + { + Content::iterator found = content_.find(depth); + + if (found != content_.end()) + { + assert(found->second != NULL); + delete found->second; + content_.erase(found); + } + } + + + void Scene2D::Apply(IVisitor& visitor) + { + for (Content::const_iterator it = content_.begin(); + it != content_.end(); ++it) + { + assert(it->second != NULL); + visitor.Visit(*it->second, it->first); + } + } + + + void Scene2D::SetSceneToCanvasTransform(const AffineTransform2D& transform) + { + // Make sure the transform is invertible before making any change + AffineTransform2D inverse = AffineTransform2D::Invert(transform); + + sceneToCanvas_ = transform; + canvasToScene_ = inverse; + } + + + void Scene2D::FitContent(unsigned int canvasWidth, + unsigned int canvasHeight) + { + Extent2D extent; + + for (Content::const_iterator it = content_.begin(); + it != content_.end(); ++it) + { + assert(it->second != NULL); + + Extent2D tmp; + if (it->second->GetBoundingBox(tmp)) + { + extent.Union(tmp); + } + } + + if (!extent.IsEmpty()) + { + double zoomX = static_cast(canvasWidth) / extent.GetWidth(); + double zoomY = static_cast(canvasHeight) / extent.GetHeight(); + + double zoom = std::min(zoomX, zoomY); + if (LinearAlgebra::IsCloseToZero(zoom)) + { + zoom = 1; + } + + double panX = extent.GetCenterX(); + double panY = extent.GetCenterY(); + + // Bring the center of the scene to (0,0) + AffineTransform2D t1 = AffineTransform2D::CreateOffset(-panX, -panY); + + // Scale the scene + AffineTransform2D t2 = AffineTransform2D::CreateScaling(zoom, zoom); + + SetSceneToCanvasTransform(AffineTransform2D::Combine(t2, t1)); + } + } +} diff -r d933fc19214a -r e36e69a380a5 Framework/Scene2D/Scene2D.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Scene2D.h Fri Apr 19 16:43:08 2019 +0200 @@ -0,0 +1,89 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 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 . + **/ + + +#pragma once + +#include "ISceneLayer.h" +#include "../Toolbox/AffineTransform2D.h" + +#include + +namespace OrthancStone +{ + class Scene2D : public boost::noncopyable + { + public: + class IVisitor : public boost::noncopyable + { + public: + virtual ~IVisitor() + { + } + + virtual void Visit(const ISceneLayer& layer, + int depth) = 0; + }; + + private: + typedef std::map Content; + + Content content_; + + AffineTransform2D sceneToCanvas_; + AffineTransform2D canvasToScene_; + + Scene2D(const Scene2D& other); + + public: + Scene2D() + { + } + + ~Scene2D(); + + Scene2D* Clone() const + { + return new Scene2D(*this); + } + + void SetLayer(int depth, + ISceneLayer* layer); // Takes ownership + + void DeleteLayer(int depth); + + void Apply(IVisitor& visitor); + + const AffineTransform2D& GetSceneToCanvasTransform() const + { + return sceneToCanvas_; + } + + const AffineTransform2D& GetCanvasToSceneTransform() const + { + return canvasToScene_; + } + + void SetSceneToCanvasTransform(const AffineTransform2D& transform); + + void FitContent(unsigned int canvasWidth, + unsigned int canvasHeight); + }; +} diff -r d933fc19214a -r e36e69a380a5 Resources/CMake/OrthancStoneConfiguration.cmake --- a/Resources/CMake/OrthancStoneConfiguration.cmake Fri Apr 19 16:17:13 2019 +0200 +++ b/Resources/CMake/OrthancStoneConfiguration.cmake Fri Apr 19 16:43:08 2019 +0200 @@ -289,6 +289,7 @@ ${ORTHANC_STONE_ROOT}/Framework/Radiography/RadiographyTextLayer.cpp ${ORTHANC_STONE_ROOT}/Framework/Radiography/RadiographyWidget.cpp ${ORTHANC_STONE_ROOT}/Framework/Radiography/RadiographyWindowingTracker.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Scene2D.cpp ${ORTHANC_STONE_ROOT}/Framework/SmartLoader.cpp ${ORTHANC_STONE_ROOT}/Framework/StoneEnumerations.cpp ${ORTHANC_STONE_ROOT}/Framework/StoneException.h