Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/Internals/OpenGLBasicPolylineRenderer.cpp @ 1790:b325761e0bd3
angle measure and undo/redo in sdl simple viewer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 17 May 2021 13:57:25 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
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 |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
593
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 |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
593
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 |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
15 * Lesser 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 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
18 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
593
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 |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 #include "OpenGLBasicPolylineRenderer.h" |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "../../OpenGL/OpenGLIncludes.h" |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 namespace OrthancStone |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 { |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 namespace Internals |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 { |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 OpenGLBasicPolylineRenderer::OpenGLBasicPolylineRenderer(OpenGL::IOpenGLContext& context, |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
655
diff
changeset
|
32 const PolylineSceneLayer& layer) : |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 context_(context) |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 { |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 layer_.Copy(layer); |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 } |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
1571 | 38 void OpenGLBasicPolylineRenderer::Render(const AffineTransform2D& transform, |
39 unsigned int canvasWidth, | |
40 unsigned int canvasHeight) | |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
42 if (!context_.IsContextLost()) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
43 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
44 AffineTransform2D t = AffineTransform2D::Combine( |
1571 | 45 AffineTransform2D::CreateOpenGLClipspace(canvasWidth, canvasHeight), |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
46 transform); |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
48 glUseProgram(0); |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
50 glBegin(GL_LINES); |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
52 for (size_t i = 0; i < layer_.GetChainsCount(); i++) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
53 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
54 const Color& color = layer_.GetColor(i); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
55 glColor3ub(color.GetRed(), color.GetGreen(), color.GetBlue()); |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
655
diff
changeset
|
56 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
57 const PolylineSceneLayer::Chain& chain = layer_.GetChain(i); |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
59 if (chain.size() > 1) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
60 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
61 ScenePoint2D previous = chain[0].Apply(t); |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
63 for (size_t j = 1; j < chain.size(); j++) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
64 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
65 ScenePoint2D p = chain[j].Apply(t); |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
67 glVertex2f(static_cast<GLfloat>(previous.GetX()), |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
68 static_cast<GLfloat>(previous.GetY())); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
69 glVertex2f(static_cast<GLfloat>(p.GetX()), |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
70 static_cast<GLfloat>(p.GetY())); |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
72 previous = p; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
73 } |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
75 if (layer_.IsClosedChain(i)) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
76 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
77 ScenePoint2D p = chain[0].Apply(t); |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
79 glVertex2f(static_cast<GLfloat>(previous.GetX()), |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
80 static_cast<GLfloat>(previous.GetY())); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
81 glVertex2f(static_cast<GLfloat>(p.GetX()), |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
82 static_cast<GLfloat>(p.GetY())); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
83 } |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 } |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 } |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
86 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
87 glEnd(); |
593
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 |
655
1e26bb5f2a02
Fixed truncating conversion warnings + fixed deletion of incomplete type
Benjamin Golinvaux <bgo@osimis.io>
parents:
593
diff
changeset
|
91 |
593
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 void OpenGLBasicPolylineRenderer::Update(const ISceneLayer& layer) |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 { |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 layer_.Copy(dynamic_cast<const PolylineSceneLayer&>(layer)); |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 } |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 } |
6bf8f881fcb5
OpenGLBasicPolylineRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 } |