Mercurial > hg > orthanc-stone
changeset 584:434ceeb0bcab
layers: InfoPanel, Polyline, Texture
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 19 Apr 2019 17:36:00 +0200 |
parents | f9ac154c5a63 |
children | b9ce24c606ae |
files | Framework/OpenGL/OpenGLShader.cpp Framework/Scene2D/ColorSceneLayer.h Framework/Scene2D/InfoPanelSceneLayer.cpp Framework/Scene2D/InfoPanelSceneLayer.h Framework/Scene2D/PolylineSceneLayer.cpp Framework/Scene2D/PolylineSceneLayer.h Framework/Scene2D/ScenePoint2D.h Framework/Scene2D/TextureSceneLayer.cpp Framework/Scene2D/TextureSceneLayer.h Resources/CMake/OrthancStoneConfiguration.cmake |
diffstat | 10 files changed, 732 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/OpenGL/OpenGLShader.cpp Fri Apr 19 17:16:37 2019 +0200 +++ b/Framework/OpenGL/OpenGLShader.cpp Fri Apr 19 17:36:00 2019 +0200 @@ -53,14 +53,15 @@ int infoLen = 0; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); - if (infoLen > 1) + if (infoLen > 0) { - char infoLog[infoLen + 1]; - glGetShaderInfoLog(shader, infoLen, NULL, infoLog); + std::string infoLog; + infoLog.resize(infoLen + 1); + glGetShaderInfoLog(shader, infoLen, NULL, &infoLog[0]); glDeleteShader(shader); throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, - "Error while creating an OpenGL shader: " + std::string(infoLog)); + "Error while creating an OpenGL shader: " + infoLog); } else {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/ColorSceneLayer.h Fri Apr 19 17:36:00 2019 +0200 @@ -0,0 +1,84 @@ +/** + * 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 <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "ISceneLayer.h" + +#include <stdint.h> + +namespace OrthancStone +{ + class ColorSceneLayer : public ISceneLayer + { + private: + uint8_t red_; + uint8_t green_; + uint8_t blue_; + + public: + ColorSceneLayer() : + red_(255), + green_(255), + blue_(255) + { + } + + void SetColor(uint8_t red, + uint8_t green, + uint8_t blue) + { + red_ = red; + green_ = green; + blue_ = blue; + } + + uint8_t GetRed() const + { + return red_; + } + + uint8_t GetGreen() const + { + return green_; + } + + uint8_t GetBlue() const + { + return blue_; + } + + float GetRedAsFloat() const + { + return static_cast<float>(red_) / 255.0f; + } + + float GetGreenAsFloat() const + { + return static_cast<float>(green_) / 255.0f; + } + + float GetBlueAsFloat() const + { + return static_cast<float>(blue_) / 255.0f; + } + }; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/InfoPanelSceneLayer.cpp Fri Apr 19 17:36:00 2019 +0200 @@ -0,0 +1,105 @@ +/** + * 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 <http://www.gnu.org/licenses/>. + **/ + + +#include "InfoPanelSceneLayer.h" + +#include <Core/Images/Image.h> +#include <Core/OrthancException.h> + +namespace OrthancStone +{ + InfoPanelSceneLayer::InfoPanelSceneLayer(const Orthanc::ImageAccessor& texture, + BitmapAnchor anchor, + bool isLinearInterpolation) : + texture_(Orthanc::Image::Clone(texture)), + anchor_(anchor), + isLinearInterpolation_(isLinearInterpolation) + { + if (texture_->GetFormat() != Orthanc::PixelFormat_RGBA32 && + texture_->GetFormat() != Orthanc::PixelFormat_RGB24) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); + } + } + + + void InfoPanelSceneLayer::ComputeAnchorLocation(int& x, + int& y, + BitmapAnchor anchor, + unsigned int textureWidth, + unsigned int textureHeight, + unsigned int canvasWidth, + unsigned int canvasHeight) + { + int tw = static_cast<int>(textureWidth); + int th = static_cast<int>(textureHeight); + int cw = static_cast<int>(canvasWidth); + int ch = static_cast<int>(canvasHeight); + + switch (anchor) + { + case BitmapAnchor_TopLeft: + case BitmapAnchor_CenterLeft: + case BitmapAnchor_BottomLeft: + x = 0; + break; + + case BitmapAnchor_TopCenter: + case BitmapAnchor_Center: + case BitmapAnchor_BottomCenter: + x = (cw - tw) / 2; + break; + + case BitmapAnchor_TopRight: + case BitmapAnchor_CenterRight: + case BitmapAnchor_BottomRight: + x = cw - tw; + break; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + + switch (anchor) + { + case BitmapAnchor_TopLeft: + case BitmapAnchor_TopCenter: + case BitmapAnchor_TopRight: + y = 0; + break; + + case BitmapAnchor_CenterLeft: + case BitmapAnchor_Center: + case BitmapAnchor_CenterRight: + y = (ch - th) / 2; + break; + + case BitmapAnchor_BottomLeft: + case BitmapAnchor_BottomCenter: + case BitmapAnchor_BottomRight: + y = ch - th; + break; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/InfoPanelSceneLayer.h Fri Apr 19 17:36:00 2019 +0200 @@ -0,0 +1,88 @@ +/** + * 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 <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "ISceneLayer.h" +#include "../StoneEnumerations.h" + +#include <Core/Images/ImageAccessor.h> + +#include <memory> + +namespace OrthancStone +{ + class InfoPanelSceneLayer : public ISceneLayer + { + private: + std::auto_ptr<Orthanc::ImageAccessor> texture_; + BitmapAnchor anchor_; + bool isLinearInterpolation_; + + public: + InfoPanelSceneLayer(const Orthanc::ImageAccessor& texture, + BitmapAnchor anchor, + bool isLinearInterpolation); + + virtual ISceneLayer* Clone() const + { + return new InfoPanelSceneLayer(*texture_, anchor_, isLinearInterpolation_); + } + + const Orthanc::ImageAccessor& GetTexture() const + { + return *texture_; + } + + BitmapAnchor GetAnchor() const + { + return anchor_; + } + + bool IsLinearInterpolation() const + { + return isLinearInterpolation_; + } + + virtual Type GetType() const + { + return Type_InfoPanel; + } + + virtual bool GetBoundingBox(Extent2D& target) const + { + return false; + } + + virtual uint64_t GetRevision() const + { + return 0; + } + + static void ComputeAnchorLocation(int& x, + int& y, + BitmapAnchor anchor, + unsigned int textureWidth, + unsigned int textureHeight, + unsigned int canvasWidth, + unsigned int canvasHeight); + }; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/PolylineSceneLayer.cpp Fri Apr 19 17:36:00 2019 +0200 @@ -0,0 +1,117 @@ +/** + * 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 <http://www.gnu.org/licenses/>. + **/ + + +#include "PolylineSceneLayer.h" + +#include <Core/OrthancException.h> + +namespace OrthancStone +{ + ISceneLayer* PolylineSceneLayer::Clone() const + { + std::auto_ptr<PolylineSceneLayer> cloned(new PolylineSceneLayer); + cloned->Copy(*this); + return cloned.release(); + } + + + void PolylineSceneLayer::SetThickness(double thickness) + { + if (thickness <= 0) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + else + { + thickness_ = thickness; + } + } + + + void PolylineSceneLayer::Copy(const PolylineSceneLayer& from) + { + SetColor(from.GetRed(), from.GetGreen(), from.GetBlue()); + chains_ = from.chains_; + closed_ = from.closed_; + thickness_ = from.thickness_; + } + + + void PolylineSceneLayer::Reserve(size_t countChains) + { + chains_.reserve(countChains); + closed_.reserve(countChains); + } + + + void PolylineSceneLayer::AddChain(const Chain& chain, + bool isClosed) + { + if (!chain.empty()) + { + chains_.push_back(chain); + closed_.push_back(isClosed); + } + } + + + const PolylineSceneLayer::Chain& PolylineSceneLayer::GetChain(size_t i) const + { + if (i < chains_.size()) + { + return chains_[i]; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + } + + + bool PolylineSceneLayer::IsClosedChain(size_t i) const + { + if (i < closed_.size()) + { + return closed_[i]; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + } + + + bool PolylineSceneLayer::GetBoundingBox(Extent2D& target) const + { + target.Reset(); + + for (size_t i = 0; i < chains_.size(); i++) + { + for (size_t j = 0; j < chains_[i].size(); j++) + { + const ScenePoint2D& p = chains_[i][j]; + target.AddPoint(p.GetX(), p.GetY()); + } + } + + return true; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/PolylineSceneLayer.h Fri Apr 19 17:36:00 2019 +0200 @@ -0,0 +1,84 @@ +/** + * 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 <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "ColorSceneLayer.h" +#include "ScenePoint2D.h" + +#include <vector> + +namespace OrthancStone +{ + class PolylineSceneLayer : public ColorSceneLayer + { + public: + typedef std::vector<ScenePoint2D> Chain; + + private: + std::vector<Chain> chains_; + std::vector<bool> closed_; + double thickness_; + + public: + PolylineSceneLayer() : + thickness_(1.0) + { + } + + virtual ISceneLayer* Clone() const; + + void SetThickness(double thickness); + + double GetThickness() const + { + return thickness_; + } + + void Copy(const PolylineSceneLayer& from); + + void Reserve(size_t countChains); + + void AddChain(const Chain& chain, + bool isClosed); + + size_t GetChainsCount() const + { + return chains_.size(); + } + + const Chain& GetChain(size_t i) const; + + bool IsClosedChain(size_t i) const; + + virtual Type GetType() const + { + return Type_Polyline; + } + + virtual bool GetBoundingBox(Extent2D& target) const; + + virtual uint64_t GetRevision() const + { + return 0; + } + }; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/ScenePoint2D.h Fri Apr 19 17:36:00 2019 +0200 @@ -0,0 +1,61 @@ +/** + * 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 <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "../Toolbox/AffineTransform2D.h" + + +namespace OrthancStone +{ + class ScenePoint2D + { + private: + double x_; + double y_; + + public: + ScenePoint2D(double x, + double y) : + x_(x), + y_(y) + { + } + + double GetX() const + { + return x_; + } + + double GetY() const + { + return y_; + } + + ScenePoint2D Apply(const AffineTransform2D& t) const + { + double x = x_; + double y = y_; + t.Apply(x, y); + return ScenePoint2D(x, y); + } + }; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/TextureSceneLayer.cpp Fri Apr 19 17:36:00 2019 +0200 @@ -0,0 +1,107 @@ +/** + * 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 <http://www.gnu.org/licenses/>. + **/ + + +#include "TextureSceneLayer.h" + +#include <Core/Images/Image.h> +#include <Core/OrthancException.h> + +namespace OrthancStone +{ + TextureSceneLayer::TextureSceneLayer(const Orthanc::ImageAccessor& texture, + double originX, // Center of the top-left pixel + double originY, + double pixelSpacingX, + double pixelSpacingY, + double angle, + bool isLinearInterpolation) : + texture_(Orthanc::Image::Clone(texture)), + originX_(originX), + originY_(originY), + pixelSpacingX_(pixelSpacingX), + pixelSpacingY_(pixelSpacingY), + angle_(angle), + isLinearInterpolation_(isLinearInterpolation) + { + if (texture_->GetFormat() != Orthanc::PixelFormat_Grayscale8 && + texture_->GetFormat() != Orthanc::PixelFormat_RGBA32 && + texture_->GetFormat() != Orthanc::PixelFormat_RGB24) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); + } + + if (pixelSpacingX_ <= 0 || + pixelSpacingY_ <= 0) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + } + + + ISceneLayer* TextureSceneLayer::Clone() const + { + return new TextureSceneLayer(*texture_, originX_, originY_, + pixelSpacingX_, pixelSpacingY_, angle_, + isLinearInterpolation_); + } + + + AffineTransform2D TextureSceneLayer::GetTransform() const + { + return AffineTransform2D::Combine( + AffineTransform2D::CreateOffset(originX_, originY_), + AffineTransform2D::CreateRotation(angle_), + AffineTransform2D::CreateScaling(pixelSpacingX_, pixelSpacingY_), + AffineTransform2D::CreateOffset(-0.5, -0.5)); + } + + + bool TextureSceneLayer::GetBoundingBox(Extent2D& target) const + { + const AffineTransform2D t = GetTransform(); + + target.Reset(); + + double x, y; + + x = 0; + y = 0; + t.Apply(x, y); + target.AddPoint(x, y); + + x = static_cast<double>(texture_->GetWidth()); + y = 0; + t.Apply(x, y); + target.AddPoint(x, y); + + x = 0; + y = static_cast<double>(texture_->GetHeight()); + t.Apply(x, y); + target.AddPoint(x, y); + + x = static_cast<double>(texture_->GetWidth()); + y = static_cast<double>(texture_->GetHeight()); + t.Apply(x, y); + target.AddPoint(x, y); + + return true; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/TextureSceneLayer.h Fri Apr 19 17:36:00 2019 +0200 @@ -0,0 +1,78 @@ +/** + * 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 <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "ISceneLayer.h" +#include "../Toolbox/AffineTransform2D.h" + +#include <Core/Images/ImageAccessor.h> +#include <memory> + +namespace OrthancStone +{ + class TextureSceneLayer : public ISceneLayer + { + private: + std::auto_ptr<Orthanc::ImageAccessor> texture_; + double originX_; + double originY_; + double pixelSpacingX_; + double pixelSpacingY_; + double angle_; + bool isLinearInterpolation_; + + public: + TextureSceneLayer(const Orthanc::ImageAccessor& texture, + double originX, // Center of the top-left pixel + double originY, + double pixelSpacingX, + double pixelSpacingY, + double angle, + bool isLinearInterpolation); + + virtual ISceneLayer* Clone() const; + + const Orthanc::ImageAccessor& GetTexture() const + { + return *texture_; + } + + AffineTransform2D GetTransform() const; + + bool IsLinearInterpolation() const + { + return isLinearInterpolation_; + } + + virtual Type GetType() const + { + return Type_Texture; + } + + virtual bool GetBoundingBox(Extent2D& target) const; + + virtual uint64_t GetRevision() const + { + return 0; + } + }; +}
--- a/Resources/CMake/OrthancStoneConfiguration.cmake Fri Apr 19 17:16:37 2019 +0200 +++ b/Resources/CMake/OrthancStoneConfiguration.cmake Fri Apr 19 17:36:00 2019 +0200 @@ -289,7 +289,10 @@ ${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/InfoPanelSceneLayer.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/PolylineSceneLayer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Scene2D.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/TextureSceneLayer.cpp ${ORTHANC_STONE_ROOT}/Framework/SmartLoader.cpp ${ORTHANC_STONE_ROOT}/Framework/StoneEnumerations.cpp ${ORTHANC_STONE_ROOT}/Framework/StoneException.h