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