Mercurial > hg > orthanc-stone
comparison Framework/Scene2D/Internals/OpenGLBasicPolylineRenderer.cpp @ 593:6bf8f881fcb5
OpenGLBasicPolylineRenderer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 26 Apr 2019 13:04:56 +0200 |
parents | |
children | 1e26bb5f2a02 |
comparison
equal
deleted
inserted
replaced
592:bbe29efd3d1c | 593:6bf8f881fcb5 |
---|---|
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-2019 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 | |
38 void OpenGLBasicPolylineRenderer::Render(const AffineTransform2D& transform) | |
39 { | |
40 AffineTransform2D t = AffineTransform2D::Combine( | |
41 AffineTransform2D::CreateOpenGLClipspace(context_.GetCanvasWidth(), context_.GetCanvasHeight()), | |
42 transform); | |
43 | |
44 glUseProgram(0); | |
45 glColor3ub(layer_.GetRed(), layer_.GetGreen(), layer_.GetBlue()); | |
46 | |
47 glBegin(GL_LINES); | |
48 | |
49 for (size_t i = 0; i < layer_.GetChainsCount(); i++) | |
50 { | |
51 const PolylineSceneLayer::Chain& chain = layer_.GetChain(i); | |
52 | |
53 if (chain.size() > 1) | |
54 { | |
55 ScenePoint2D previous = chain[0].Apply(t); | |
56 | |
57 for (size_t j = 1; j < chain.size(); j++) | |
58 { | |
59 ScenePoint2D p = chain[j].Apply(t); | |
60 | |
61 glVertex2f(previous.GetX(), previous.GetY()); | |
62 glVertex2f(p.GetX(), p.GetY()); | |
63 | |
64 previous = p; | |
65 } | |
66 | |
67 if (layer_.IsClosedChain(i)) | |
68 { | |
69 ScenePoint2D p = chain[0].Apply(t); | |
70 | |
71 glVertex2f(previous.GetX(), previous.GetY()); | |
72 glVertex2f(p.GetX(), p.GetY()); | |
73 } | |
74 } | |
75 } | |
76 | |
77 glEnd(); | |
78 } | |
79 | |
80 | |
81 void OpenGLBasicPolylineRenderer::Update(const ISceneLayer& layer) | |
82 { | |
83 layer_.Copy(dynamic_cast<const PolylineSceneLayer&>(layer)); | |
84 } | |
85 } | |
86 } |