# HG changeset patch # User Sebastien Jodogne # Date 1556284271 -7200 # Node ID 6e471e6cf09bca15e67a1cc0785204d7289ab644 # Parent 9807ed3d3e03feed23bdf358b186daeeca920869 CairoPolylineRenderer, SdlOpenGLWindow diff -r 9807ed3d3e03 -r 6e471e6cf09b Applications/Sdl/SdlOpenGLWindow.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Applications/Sdl/SdlOpenGLWindow.cpp Fri Apr 26 15:11:11 2019 +0200 @@ -0,0 +1,87 @@ +/** + * 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 "SdlOpenGLWindow.h" + +#if ORTHANC_ENABLE_SDL == 1 + +#include + +namespace OrthancStone +{ + SdlOpenGLWindow::SdlOpenGLWindow(const char* title, + unsigned int width, + unsigned int height) : + window_(title, width, height, true /* enable OpenGL */) + { + context_ = SDL_GL_CreateContext(window_.GetObject()); + + if (context_ == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, + "Cannot initialize OpenGL"); + } + } + + + SdlOpenGLWindow::~SdlOpenGLWindow() + { + SDL_GL_DeleteContext(context_); + } + + + void SdlOpenGLWindow::MakeCurrent() + { + if (SDL_GL_MakeCurrent(window_.GetObject(), context_) != 0) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, + "Cannot set current OpenGL context"); + } + + // This makes our buffer swap syncronized with the monitor's vertical refresh + SDL_GL_SetSwapInterval(1); + } + + + void SdlOpenGLWindow::SwapBuffer() + { + // Swap our buffer to display the current contents of buffer on screen + SDL_GL_SwapWindow(window_.GetObject()); + } + + + unsigned int SdlOpenGLWindow::GetCanvasWidth() + { + int w = 0; + SDL_GL_GetDrawableSize(window_.GetObject(), &w, NULL); + return static_cast(w); + } + + + unsigned int SdlOpenGLWindow::GetCanvasHeight() + { + int h = 0; + SDL_GL_GetDrawableSize(window_.GetObject(), NULL, &h); + return static_cast(h); + } +} + +#endif diff -r 9807ed3d3e03 -r 6e471e6cf09b Applications/Sdl/SdlOpenGLWindow.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Applications/Sdl/SdlOpenGLWindow.h Fri Apr 26 15:11:11 2019 +0200 @@ -0,0 +1,59 @@ +/** + * 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 ORTHANC_ENABLE_SDL == 1 + +#include "../../Framework/OpenGL/IOpenGLContext.h" +#include "SdlWindow.h" + +namespace OrthancStone +{ + class SdlOpenGLWindow : public OpenGL::IOpenGLContext + { + private: + SdlWindow window_; + SDL_GLContext context_; + + public: + SdlOpenGLWindow(const char* title, + unsigned int width, + unsigned int height); + + ~SdlOpenGLWindow(); + + SdlWindow& GetWindow() + { + return window_; + } + + virtual void MakeCurrent(); + + virtual void SwapBuffer(); + + virtual unsigned int GetCanvasWidth(); + + virtual unsigned int GetCanvasHeight(); + }; +} + +#endif diff -r 9807ed3d3e03 -r 6e471e6cf09b Framework/Scene2D/Internals/CairoBaseRenderer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/CairoBaseRenderer.h Fri Apr 26 15:11:11 2019 +0200 @@ -0,0 +1,63 @@ +/** + * 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 "ICairoContextProvider.h" +#include "CompositorHelper.h" + +namespace OrthancStone +{ + namespace Internals + { + class CairoBaseRenderer : public CompositorHelper::ILayerRenderer + { + private: + ICairoContextProvider& target_; + std::auto_ptr layer_; + + protected: + template + const T& GetLayer() const + { + return dynamic_cast(*layer_); + } + + cairo_t* GetCairoContext() const + { + return target_.GetCairoContext(); + } + + public: + CairoBaseRenderer(ICairoContextProvider& target, + const ISceneLayer& layer) : + target_(target) + { + Update(layer); + } + + virtual void Update(const ISceneLayer& layer) + { + layer_.reset(layer.Clone()); + } + }; + } +} diff -r 9807ed3d3e03 -r 6e471e6cf09b Framework/Scene2D/Internals/CairoPolylineRenderer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/CairoPolylineRenderer.cpp Fri Apr 26 15:11:11 2019 +0200 @@ -0,0 +1,70 @@ +/** + * 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 "CairoPolylineRenderer.h" + +#include "../PolylineSceneLayer.h" + +namespace OrthancStone +{ + namespace Internals + { + void CairoPolylineRenderer::Render(const AffineTransform2D& transform) + { + const PolylineSceneLayer& layer = GetLayer(); + + cairo_t* cr = GetCairoContext(); + + cairo_set_source_rgb(cr, layer.GetRedAsFloat(), layer.GetGreenAsFloat(), layer.GetBlueAsFloat()); + cairo_set_line_width(cr, layer.GetThickness()); + + for (size_t i = 0; i < layer.GetChainsCount(); i++) + { + const PolylineSceneLayer::Chain& chain = layer.GetChain(i); + + if (!chain.empty()) + { + for (size_t j = 0; j < chain.size(); j++) + { + ScenePoint2D p = chain[j].Apply(transform); + + if (j == 0) + { + cairo_move_to(cr, p.GetX(), p.GetY()); + } + else + { + cairo_line_to(cr, p.GetX(), p.GetY()); + } + } + + if (layer.IsClosedChain(i)) + { + ScenePoint2D p = chain[0].Apply(transform); + cairo_line_to(cr, p.GetX(), p.GetY()); + } + } + } + + cairo_stroke(cr); + } + } +} diff -r 9807ed3d3e03 -r 6e471e6cf09b Framework/Scene2D/Internals/CairoPolylineRenderer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/CairoPolylineRenderer.h Fri Apr 26 15:11:11 2019 +0200 @@ -0,0 +1,42 @@ +/** + * 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 "CairoBaseRenderer.h" + +namespace OrthancStone +{ + namespace Internals + { + class CairoPolylineRenderer : public CairoBaseRenderer + { + public: + CairoPolylineRenderer(ICairoContextProvider& target, + const ISceneLayer& layer) : + CairoBaseRenderer(target, layer) + { + } + + virtual void Render(const AffineTransform2D& transform); + }; + } +} diff -r 9807ed3d3e03 -r 6e471e6cf09b Framework/Scene2D/Internals/ICairoContextProvider.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/ICairoContextProvider.h Fri Apr 26 15:11:11 2019 +0200 @@ -0,0 +1,46 @@ +/** + * 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 +#include +#include + +namespace OrthancStone +{ + namespace Internals + { + class ICairoContextProvider : public boost::noncopyable + { + public: + virtual ~ICairoContextProvider() + { + } + + virtual cairo_t* GetCairoContext() = 0; + + virtual unsigned int GetCairoWidth() = 0; + + virtual unsigned int GetCairoHeight() = 0; + }; + } +} diff -r 9807ed3d3e03 -r 6e471e6cf09b Resources/CMake/OrthancStoneConfiguration.cmake --- a/Resources/CMake/OrthancStoneConfiguration.cmake Fri Apr 26 14:45:47 2019 +0200 +++ b/Resources/CMake/OrthancStoneConfiguration.cmake Fri Apr 26 15:11:11 2019 +0200 @@ -213,10 +213,11 @@ ) if (ENABLE_SDL) list(APPEND APPLICATIONS_SOURCES - ${ORTHANC_STONE_ROOT}/Applications/Sdl/SdlStoneApplicationRunner.cpp + ${ORTHANC_STONE_ROOT}/Applications/Sdl/SdlCairoSurface.cpp ${ORTHANC_STONE_ROOT}/Applications/Sdl/SdlEngine.cpp - ${ORTHANC_STONE_ROOT}/Applications/Sdl/SdlCairoSurface.cpp + ${ORTHANC_STONE_ROOT}/Applications/Sdl/SdlOpenGLWindow.cpp ${ORTHANC_STONE_ROOT}/Applications/Sdl/SdlOrthancSurface.cpp + ${ORTHANC_STONE_ROOT}/Applications/Sdl/SdlStoneApplicationRunner.cpp ${ORTHANC_STONE_ROOT}/Applications/Sdl/SdlWindow.cpp ) endif() @@ -259,6 +260,7 @@ ${ORTHANC_STONE_ROOT}/Framework/Scene2D/ColorTextureSceneLayer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/FloatTextureSceneLayer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/InfoPanelSceneLayer.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/CairoPolylineRenderer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/CompositorHelper.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/PolylineSceneLayer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Scene2D.cpp