Mercurial > hg > orthanc-stone
annotate Framework/Scene2D/OpenGLCompositor.cpp @ 867:fe96057e97b9 toa2019062502
Added tag toa2019062501 for changeset c71ef52602a0
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 25 Jun 2019 17:55:50 +0200 |
parents | 266e2b0b9abc |
children | 80829436ce0c 77c96ba899f9 |
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 | |
22 #include "OpenGLCompositor.h" | |
23 | |
24 #include "Internals/OpenGLAdvancedPolylineRenderer.h" | |
25 #include "Internals/OpenGLBasicPolylineRenderer.h" | |
26 #include "Internals/OpenGLColorTextureRenderer.h" | |
27 #include "Internals/OpenGLFloatTextureRenderer.h" | |
28 #include "Internals/OpenGLInfoPanelRenderer.h" | |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
29 #include "Internals/OpenGLLookupTableTextureRenderer.h" |
594 | 30 #include "Internals/OpenGLTextRenderer.h" |
31 | |
32 namespace OrthancStone | |
33 { | |
34 class OpenGLCompositor::Font : public boost::noncopyable | |
35 { | |
36 private: | |
37 std::auto_ptr<GlyphTextureAlphabet> alphabet_; | |
38 std::auto_ptr<OpenGL::OpenGLTexture> texture_; | |
39 | |
40 public: | |
41 Font(const GlyphBitmapAlphabet& dict) | |
42 { | |
43 alphabet_.reset(new GlyphTextureAlphabet(dict)); | |
44 texture_.reset(new OpenGL::OpenGLTexture); | |
45 | |
46 std::auto_ptr<Orthanc::ImageAccessor> bitmap(alphabet_->ReleaseTexture()); | |
47 texture_->Load(*bitmap, true /* enable linear interpolation */); | |
48 } | |
49 | |
50 OpenGL::OpenGLTexture& GetTexture() const | |
51 { | |
52 assert(texture_.get() != NULL); | |
53 return *texture_; | |
54 } | |
55 | |
56 const GlyphTextureAlphabet& GetAlphabet() const | |
57 { | |
58 assert(alphabet_.get() != NULL); | |
59 return *alphabet_; | |
60 } | |
61 }; | |
62 | |
63 | |
64 const OpenGLCompositor::Font* OpenGLCompositor::GetFont(size_t fontIndex) const | |
65 { | |
66 Fonts::const_iterator found = fonts_.find(fontIndex); | |
67 | |
68 if (found == fonts_.end()) | |
69 { | |
70 return NULL; // Unknown font, nothing should be drawn | |
71 } | |
72 else | |
73 { | |
74 assert(found->second != NULL); | |
75 return found->second; | |
76 } | |
77 } | |
78 | |
79 | |
80 Internals::CompositorHelper::ILayerRenderer* OpenGLCompositor::Create(const ISceneLayer& layer) | |
81 { | |
82 switch (layer.GetType()) | |
83 { | |
84 case ISceneLayer::Type_InfoPanel: | |
85 return new Internals::OpenGLInfoPanelRenderer | |
86 (context_, colorTextureProgram_, dynamic_cast<const InfoPanelSceneLayer&>(layer)); | |
87 | |
88 case ISceneLayer::Type_ColorTexture: | |
89 return new Internals::OpenGLColorTextureRenderer | |
90 (context_, colorTextureProgram_, dynamic_cast<const ColorTextureSceneLayer&>(layer)); | |
91 | |
92 case ISceneLayer::Type_FloatTexture: | |
93 return new Internals::OpenGLFloatTextureRenderer | |
94 (context_, floatTextureProgram_, dynamic_cast<const FloatTextureSceneLayer&>(layer)); | |
95 | |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
96 case ISceneLayer::Type_LookupTableTexture: |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
97 return new Internals::OpenGLLookupTableTextureRenderer |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
617
diff
changeset
|
98 (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
|
99 |
594 | 100 case ISceneLayer::Type_Polyline: |
101 return new Internals::OpenGLAdvancedPolylineRenderer | |
102 (context_, linesProgram_, dynamic_cast<const PolylineSceneLayer&>(layer)); | |
103 //return new Internals::OpenGLBasicPolylineRenderer(context_, dynamic_cast<const PolylineSceneLayer&>(layer)); | |
104 | |
105 case ISceneLayer::Type_Text: | |
106 { | |
107 const TextSceneLayer& l = dynamic_cast<const TextSceneLayer&>(layer); | |
108 const Font* font = GetFont(l.GetFontIndex()); | |
109 if (font == NULL) | |
110 { | |
111 return NULL; | |
112 } | |
113 else | |
114 { | |
115 return new Internals::OpenGLTextRenderer | |
116 (context_, textProgram_, font->GetAlphabet(), font->GetTexture(), l); | |
117 } | |
118 } | |
119 | |
120 default: | |
121 return NULL; | |
122 } | |
123 } | |
124 | |
125 | |
126 OpenGLCompositor::OpenGLCompositor(OpenGL::IOpenGLContext& context, | |
600
6129b1e5ba42
BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
598
diff
changeset
|
127 const Scene2D& scene) : |
594 | 128 context_(context), |
129 helper_(scene, *this), | |
130 colorTextureProgram_(context), | |
131 floatTextureProgram_(context), | |
132 linesProgram_(context), | |
133 textProgram_(context), | |
134 canvasWidth_(0), | |
135 canvasHeight_(0) | |
136 { | |
137 UpdateSize(); | |
138 } | |
139 | |
140 | |
141 OpenGLCompositor::~OpenGLCompositor() | |
142 { | |
143 for (Fonts::iterator it = fonts_.begin(); it != fonts_.end(); ++it) | |
144 { | |
145 assert(it->second != NULL); | |
146 delete it->second; | |
147 } | |
148 } | |
149 | |
150 | |
151 void OpenGLCompositor::UpdateSize() | |
152 { | |
153 canvasWidth_ = context_.GetCanvasWidth(); | |
154 canvasHeight_ = context_.GetCanvasHeight(); | |
155 | |
156 context_.MakeCurrent(); | |
157 glViewport(0, 0, canvasWidth_, canvasHeight_); | |
158 } | |
159 | |
160 | |
161 void OpenGLCompositor::Refresh() | |
162 { | |
163 context_.MakeCurrent(); | |
164 | |
165 glClearColor(0, 0, 0, 1); | |
166 glClear(GL_COLOR_BUFFER_BIT); | |
167 | |
168 helper_.Refresh(canvasWidth_, canvasHeight_); | |
169 | |
170 context_.SwapBuffer(); | |
171 } | |
172 | |
173 | |
174 void OpenGLCompositor::SetFont(size_t index, | |
175 const GlyphBitmapAlphabet& dict) | |
176 { | |
177 std::auto_ptr<Font> font(new Font(dict)); | |
178 | |
179 Fonts::iterator found = fonts_.find(index); | |
180 | |
181 if (found == fonts_.end()) | |
182 { | |
183 fonts_[index] = font.release(); | |
184 } | |
185 else | |
186 { | |
187 assert(found->second != NULL); | |
188 delete found->second; | |
189 | |
190 found->second = font.release(); | |
191 } | |
192 } | |
193 | |
194 | |
195 #if ORTHANC_ENABLE_LOCALE == 1 | |
196 void OpenGLCompositor::SetFont(size_t index, | |
197 Orthanc::EmbeddedResources::FileResourceId resource, | |
198 unsigned int fontSize, | |
199 Orthanc::Encoding codepage) | |
200 { | |
201 FontRenderer renderer; | |
598 | 202 renderer.LoadFont(resource, fontSize); |
594 | 203 |
204 GlyphBitmapAlphabet dict; | |
205 dict.LoadCodepage(renderer, codepage); | |
206 | |
207 SetFont(index, dict); | |
208 } | |
209 #endif | |
617 | 210 |
211 | |
212 ScenePoint2D OpenGLCompositor::GetPixelCenterCoordinates(int x, int y) const | |
213 { | |
214 return ScenePoint2D( | |
215 static_cast<double>(x) + 0.5 - static_cast<double>(canvasWidth_) / 2.0, | |
216 static_cast<double>(y) + 0.5 - static_cast<double>(canvasHeight_) / 2.0); | |
217 } | |
594 | 218 } |