comparison OrthancStone/Sources/Scene2D/Internals/OpenGLBasicPolylineRenderer.cpp @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Scene2D/Internals/OpenGLBasicPolylineRenderer.cpp@2d8ab34c8c91
children 85e117739eca
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "OpenGLBasicPolylineRenderer.h"
23
24 #include "../../OpenGL/OpenGLIncludes.h"
25
26 namespace OrthancStone
27 {
28 namespace Internals
29 {
30 OpenGLBasicPolylineRenderer::OpenGLBasicPolylineRenderer(OpenGL::IOpenGLContext& context,
31 const PolylineSceneLayer& layer) :
32 context_(context)
33 {
34 layer_.Copy(layer);
35 }
36
37 void OpenGLBasicPolylineRenderer::Render(const AffineTransform2D& transform)
38 {
39 if (!context_.IsContextLost())
40 {
41 AffineTransform2D t = AffineTransform2D::Combine(
42 AffineTransform2D::CreateOpenGLClipspace(context_.GetCanvasWidth(), context_.GetCanvasHeight()),
43 transform);
44
45 glUseProgram(0);
46
47 glBegin(GL_LINES);
48
49 for (size_t i = 0; i < layer_.GetChainsCount(); i++)
50 {
51 const Color& color = layer_.GetColor(i);
52 glColor3ub(color.GetRed(), color.GetGreen(), color.GetBlue());
53
54 const PolylineSceneLayer::Chain& chain = layer_.GetChain(i);
55
56 if (chain.size() > 1)
57 {
58 ScenePoint2D previous = chain[0].Apply(t);
59
60 for (size_t j = 1; j < chain.size(); j++)
61 {
62 ScenePoint2D p = chain[j].Apply(t);
63
64 glVertex2f(static_cast<GLfloat>(previous.GetX()),
65 static_cast<GLfloat>(previous.GetY()));
66 glVertex2f(static_cast<GLfloat>(p.GetX()),
67 static_cast<GLfloat>(p.GetY()));
68
69 previous = p;
70 }
71
72 if (layer_.IsClosedChain(i))
73 {
74 ScenePoint2D p = chain[0].Apply(t);
75
76 glVertex2f(static_cast<GLfloat>(previous.GetX()),
77 static_cast<GLfloat>(previous.GetY()));
78 glVertex2f(static_cast<GLfloat>(p.GetX()),
79 static_cast<GLfloat>(p.GetY()));
80 }
81 }
82 }
83
84 glEnd();
85 }
86 }
87
88
89 void OpenGLBasicPolylineRenderer::Update(const ISceneLayer& layer)
90 {
91 layer_.Copy(dynamic_cast<const PolylineSceneLayer&>(layer));
92 }
93 }
94 }