Mercurial > hg > orthanc-stone
annotate Framework/Scene2D/Internals/OpenGLBasicPolylineRenderer.cpp @ 920:5ca418d6579e refactor-viewport-controller
Close branch refactor-viewport-controller.
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 19 Jul 2019 14:15:49 +0000 |
parents | 1e26bb5f2a02 |
children | 61ba4b504e9a |
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, |
655
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
593
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 glColor3ub(layer_.GetRed(), layer_.GetGreen(), layer_.GetBlue()); |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 glBegin(GL_LINES); |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 for (size_t i = 0; i < layer_.GetChainsCount(); i++) |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 const PolylineSceneLayer::Chain& chain = layer_.GetChain(i); |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 if (chain.size() > 1) |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 { |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 ScenePoint2D previous = chain[0].Apply(t); |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 for (size_t j = 1; j < chain.size(); j++) |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 { |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 ScenePoint2D p = chain[j].Apply(t); |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
655
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
593
diff
changeset
|
61 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
|
62 static_cast<GLfloat>(previous.GetY())); |
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
593
diff
changeset
|
63 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
|
64 static_cast<GLfloat>(p.GetY())); |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 previous = p; |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 } |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 if (layer_.IsClosedChain(i)) |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 { |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 ScenePoint2D p = chain[0].Apply(t); |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 |
655
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
593
diff
changeset
|
73 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
|
74 static_cast<GLfloat>(previous.GetY())); |
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
593
diff
changeset
|
75 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
|
76 static_cast<GLfloat>(p.GetY())); |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 } |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 } |
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 glEnd(); |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 } |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 |
655
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
593
diff
changeset
|
84 |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 void OpenGLBasicPolylineRenderer::Update(const ISceneLayer& layer) |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 { |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 layer_.Copy(dynamic_cast<const PolylineSceneLayer&>(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 } |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 } |