Mercurial > hg > orthanc-stone
annotate Framework/Scene2D/OpenGLCompositor.cpp @ 999:2d69b8bee484
Added tests for Dicom structure set classes (loaders and utils)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 20 Sep 2019 11:58:33 +0200 |
parents | 32eaf4929b08 |
children | d10d2acb8a02 2d8ab34c8c91 |
rev | line source |
---|---|
594 | 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 #include "OpenGLCompositor.h" | |
22 | |
23 #include "Internals/OpenGLAdvancedPolylineRenderer.h" | |
24 #include "Internals/OpenGLBasicPolylineRenderer.h" | |
25 #include "Internals/OpenGLColorTextureRenderer.h" | |
26 #include "Internals/OpenGLFloatTextureRenderer.h" | |
27 #include "Internals/OpenGLInfoPanelRenderer.h" | |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
28 #include "Internals/OpenGLLookupTableTextureRenderer.h" |
594 | 29 #include "Internals/OpenGLTextRenderer.h" |
30 | |
31 namespace OrthancStone | |
32 { | |
33 class OpenGLCompositor::Font : public boost::noncopyable | |
34 { | |
35 private: | |
36 std::auto_ptr<GlyphTextureAlphabet> alphabet_; | |
37 std::auto_ptr<OpenGL::OpenGLTexture> texture_; | |
38 | |
39 public: | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
40 Font(OpenGL::IOpenGLContext& context, const GlyphBitmapAlphabet& dict) |
594 | 41 { |
42 alphabet_.reset(new GlyphTextureAlphabet(dict)); | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
43 texture_.reset(new OpenGL::OpenGLTexture(context)); |
594 | 44 |
45 std::auto_ptr<Orthanc::ImageAccessor> bitmap(alphabet_->ReleaseTexture()); | |
46 texture_->Load(*bitmap, true /* enable linear interpolation */); | |
47 } | |
48 | |
49 OpenGL::OpenGLTexture& GetTexture() const | |
50 { | |
51 assert(texture_.get() != NULL); | |
52 return *texture_; | |
53 } | |
54 | |
55 const GlyphTextureAlphabet& GetAlphabet() const | |
56 { | |
57 assert(alphabet_.get() != NULL); | |
58 return *alphabet_; | |
59 } | |
60 }; | |
61 | |
62 const OpenGLCompositor::Font* OpenGLCompositor::GetFont(size_t fontIndex) const | |
63 { | |
64 Fonts::const_iterator found = fonts_.find(fontIndex); | |
65 | |
66 if (found == fonts_.end()) | |
67 { | |
68 return NULL; // Unknown font, nothing should be drawn | |
69 } | |
70 else | |
71 { | |
72 assert(found->second != NULL); | |
73 return found->second; | |
74 } | |
75 } | |
76 | |
77 Internals::CompositorHelper::ILayerRenderer* OpenGLCompositor::Create(const ISceneLayer& layer) | |
78 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
79 if (!context_.IsContextLost()) |
594 | 80 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
81 switch (layer.GetType()) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
82 { |
594 | 83 case ISceneLayer::Type_InfoPanel: |
84 return new Internals::OpenGLInfoPanelRenderer | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
85 (context_, colorTextureProgram_, dynamic_cast<const InfoPanelSceneLayer&>(layer)); |
594 | 86 |
87 case ISceneLayer::Type_ColorTexture: | |
88 return new Internals::OpenGLColorTextureRenderer | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
89 (context_, colorTextureProgram_, dynamic_cast<const ColorTextureSceneLayer&>(layer)); |
594 | 90 |
91 case ISceneLayer::Type_FloatTexture: | |
92 return new Internals::OpenGLFloatTextureRenderer | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
93 (context_, floatTextureProgram_, dynamic_cast<const FloatTextureSceneLayer&>(layer)); |
594 | 94 |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
95 case ISceneLayer::Type_LookupTableTexture: |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
96 return new Internals::OpenGLLookupTableTextureRenderer |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
97 (context_, colorTextureProgram_, dynamic_cast<const LookupTableTextureSceneLayer&>(layer)); |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
98 |
594 | 99 case ISceneLayer::Type_Polyline: |
100 return new Internals::OpenGLAdvancedPolylineRenderer | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
101 (context_, linesProgram_, dynamic_cast<const PolylineSceneLayer&>(layer)); |
594 | 102 //return new Internals::OpenGLBasicPolylineRenderer(context_, dynamic_cast<const PolylineSceneLayer&>(layer)); |
103 | |
104 case ISceneLayer::Type_Text: | |
105 { | |
106 const TextSceneLayer& l = dynamic_cast<const TextSceneLayer&>(layer); | |
107 const Font* font = GetFont(l.GetFontIndex()); | |
108 if (font == NULL) | |
109 { | |
949
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
110 LOG(WARNING) << "There is no font at index " << l.GetFontIndex(); |
594 | 111 return NULL; |
112 } | |
113 else | |
114 { | |
115 return new Internals::OpenGLTextRenderer | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
116 (context_, textProgram_, font->GetAlphabet(), font->GetTexture(), l); |
594 | 117 } |
118 } | |
119 | |
120 default: | |
121 return NULL; | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
122 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
123 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
124 else |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
125 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
126 // context is lost. returning null. |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
127 return NULL; |
594 | 128 } |
129 } | |
130 | |
131 OpenGLCompositor::OpenGLCompositor(OpenGL::IOpenGLContext& context, | |
600
6129b1e5ba42
BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
598
diff
changeset
|
132 const Scene2D& scene) : |
594 | 133 context_(context), |
134 helper_(scene, *this), | |
135 colorTextureProgram_(context), | |
136 floatTextureProgram_(context), | |
137 linesProgram_(context), | |
138 textProgram_(context), | |
139 canvasWidth_(0), | |
140 canvasHeight_(0) | |
141 { | |
142 } | |
143 | |
144 OpenGLCompositor::~OpenGLCompositor() | |
145 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
146 if (!context_.IsContextLost()) |
594 | 147 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
148 context_.MakeCurrent(); // this can throw if context lost! |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
149 for (Fonts::iterator it = fonts_.begin(); it != fonts_.end(); ++it) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
150 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
151 assert(it->second != NULL); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
152 delete it->second; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
153 } |
594 | 154 } |
155 } | |
156 | |
890
77c96ba899f9
removing OpenGLCompositor::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
841
diff
changeset
|
157 void OpenGLCompositor::Refresh() |
594 | 158 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
159 if (!context_.IsContextLost()) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
160 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
161 context_.MakeCurrent(); // this can throw if context lost! |
892
50cd372e2460
fix OpenGL context for fonts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
891
diff
changeset
|
162 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
163 canvasWidth_ = context_.GetCanvasWidth(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
164 canvasHeight_ = context_.GetCanvasHeight(); |
594 | 165 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
166 glViewport(0, 0, canvasWidth_, canvasHeight_); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
167 glClearColor(0, 0, 0, 1); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
168 glClear(GL_COLOR_BUFFER_BIT); |
594 | 169 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
170 helper_.Refresh(canvasWidth_, canvasHeight_); |
594 | 171 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
172 context_.SwapBuffer(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
173 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
174 |
594 | 175 } |
176 | |
177 void OpenGLCompositor::SetFont(size_t index, | |
178 const GlyphBitmapAlphabet& dict) | |
179 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
180 if (!context_.IsContextLost()) |
594 | 181 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
182 context_.MakeCurrent(); // this can throw if context lost |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
183 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
184 std::auto_ptr<Font> font(new Font(context_, dict)); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
185 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
186 Fonts::iterator found = fonts_.find(index); |
594 | 187 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
188 if (found == fonts_.end()) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
189 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
190 fonts_[index] = font.release(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
191 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
192 else |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
193 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
194 assert(found->second != NULL); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
195 delete found->second; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
196 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
197 found->second = font.release(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
198 } |
594 | 199 } |
200 } | |
201 | |
202 #if ORTHANC_ENABLE_LOCALE == 1 | |
203 void OpenGLCompositor::SetFont(size_t index, | |
204 Orthanc::EmbeddedResources::FileResourceId resource, | |
205 unsigned int fontSize, | |
206 Orthanc::Encoding codepage) | |
207 { | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
208 if (!context_.IsContextLost()) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
209 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
210 FontRenderer renderer; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
211 renderer.LoadFont(resource, fontSize); |
594 | 212 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
213 GlyphBitmapAlphabet dict; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
214 dict.LoadCodepage(renderer, codepage); |
594 | 215 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
216 SetFont(index, dict); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
217 } |
594 | 218 } |
219 #endif | |
220 } |