# HG changeset patch # User Sebastien Jodogne # Date 1555688160 -7200 # Node ID 434ceeb0bcab053e053e0b0defd26a470a2e29b6 # Parent f9ac154c5a63931fc75bfaf538b8397cc117f72f layers: InfoPanel, Polyline, Texture diff -r f9ac154c5a63 -r 434ceeb0bcab Framework/OpenGL/OpenGLShader.cpp --- 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 { diff -r f9ac154c5a63 -r 434ceeb0bcab Framework/Scene2D/ColorSceneLayer.h --- /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 . + **/ + + +#pragma once + +#include "ISceneLayer.h" + +#include + +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(red_) / 255.0f; + } + + float GetGreenAsFloat() const + { + return static_cast(green_) / 255.0f; + } + + float GetBlueAsFloat() const + { + return static_cast(blue_) / 255.0f; + } + }; +} diff -r f9ac154c5a63 -r 434ceeb0bcab Framework/Scene2D/InfoPanelSceneLayer.cpp --- /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 . + **/ + + +#include "InfoPanelSceneLayer.h" + +#include +#include + +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(textureWidth); + int th = static_cast(textureHeight); + int cw = static_cast(canvasWidth); + int ch = static_cast(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); + } + } +} diff -r f9ac154c5a63 -r 434ceeb0bcab Framework/Scene2D/InfoPanelSceneLayer.h --- /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 . + **/ + + +#pragma once + +#include "ISceneLayer.h" +#include "../StoneEnumerations.h" + +#include + +#include + +namespace OrthancStone +{ + class InfoPanelSceneLayer : public ISceneLayer + { + private: + std::auto_ptr 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); + }; +} diff -r f9ac154c5a63 -r 434ceeb0bcab Framework/Scene2D/PolylineSceneLayer.cpp --- /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 . + **/ + + +#include "PolylineSceneLayer.h" + +#include + +namespace OrthancStone +{ + ISceneLayer* PolylineSceneLayer::Clone() const + { + std::auto_ptr 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; + } +} diff -r f9ac154c5a63 -r 434ceeb0bcab Framework/Scene2D/PolylineSceneLayer.h --- /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 . + **/ + + +#pragma once + +#include "ColorSceneLayer.h" +#include "ScenePoint2D.h" + +#include + +namespace OrthancStone +{ + class PolylineSceneLayer : public ColorSceneLayer + { + public: + typedef std::vector Chain; + + private: + std::vector chains_; + std::vector 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; + } + }; +} diff -r f9ac154c5a63 -r 434ceeb0bcab Framework/Scene2D/ScenePoint2D.h --- /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 . + **/ + + +#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); + } + }; +} diff -r f9ac154c5a63 -r 434ceeb0bcab Framework/Scene2D/TextureSceneLayer.cpp --- /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 . + **/ + + +#include "TextureSceneLayer.h" + +#include +#include + +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(texture_->GetWidth()); + y = 0; + t.Apply(x, y); + target.AddPoint(x, y); + + x = 0; + y = static_cast(texture_->GetHeight()); + t.Apply(x, y); + target.AddPoint(x, y); + + x = static_cast(texture_->GetWidth()); + y = static_cast(texture_->GetHeight()); + t.Apply(x, y); + target.AddPoint(x, y); + + return true; + } +} diff -r f9ac154c5a63 -r 434ceeb0bcab Framework/Scene2D/TextureSceneLayer.h --- /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 . + **/ + + +#pragma once + +#include "ISceneLayer.h" +#include "../Toolbox/AffineTransform2D.h" + +#include +#include + +namespace OrthancStone +{ + class TextureSceneLayer : public ISceneLayer + { + private: + std::auto_ptr 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; + } + }; +} diff -r f9ac154c5a63 -r 434ceeb0bcab Resources/CMake/OrthancStoneConfiguration.cmake --- 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