annotate OrthancStone/Sources/Fonts/OpenGLTextCoordinates.cpp @ 2039:e0906b7c67b9 deep-learning

const
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 28 Jan 2023 15:48:01 +0100
parents 7053b8a0aaec
children 07964689cb0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
577
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1871
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
577
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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: 1596
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
577
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * 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: 1596
diff changeset
15 * 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: 1596
diff changeset
16 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
17 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * 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: 1596
diff changeset
19 * 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: 1596
diff changeset
20 * <http://www.gnu.org/licenses/>.
577
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "OpenGLTextCoordinates.h"
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
26 #include <OrthancException.h>
577
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 namespace OrthancStone
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace OpenGL
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 void OpenGLTextCoordinates::Visit(uint32_t unicode,
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 int x,
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 int y,
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 unsigned int width,
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 unsigned int height,
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 const Orthanc::IDynamicObject* payload)
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 // Rendering coordinates
693
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 577
diff changeset
40 float rx1 = static_cast<float>(x - box_.GetLeft());
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 577
diff changeset
41 float ry1 = static_cast<float>(y - box_.GetTop());
577
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 float rx2 = rx1 + static_cast<float>(width);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 float ry2 = ry1 + static_cast<float>(height);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 // Texture coordinates
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 assert(payload != NULL);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 const GlyphTextureAlphabet::TextureLocation& location =
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 *dynamic_cast<const GlyphTextureAlphabet::TextureLocation*>(payload);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 float tx1 = location.GetX() / textureWidth_;
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 float ty1 = location.GetY() / textureHeight_;
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 float tx2 = tx1 + (static_cast<float>(width) / textureWidth_);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 float ty2 = ty1 + (static_cast<float>(height) / textureHeight_);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 const float rpos[6][2] = {
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 { rx1, ry1 },
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 { rx1, ry2 },
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 { rx2, ry1 },
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 { rx2, ry1 },
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 { rx1, ry2 },
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 { rx2, ry2 }
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 };
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 const float tpos[6][2] = {
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 { tx1, ty1 },
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 { tx1, ty2 },
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 { tx2, ty1 },
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 { tx2, ty1 },
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 { tx1, ty2 },
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 { tx2, ty2 }
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 };
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 for (unsigned int i = 0; i < 6; i++)
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 renderingCoords_.push_back(rpos[i][0]);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 renderingCoords_.push_back(rpos[i][1]);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 textureCoords_.push_back(tpos[i][0]);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 textureCoords_.push_back(tpos[i][1]);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 OpenGLTextCoordinates::OpenGLTextCoordinates(const GlyphTextureAlphabet& alphabet,
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 const std::string& utf8) :
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 box_(alphabet.GetAlphabet(), utf8),
693
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 577
diff changeset
86 textureWidth_(static_cast<float>(alphabet.GetTextureWidth())),
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 577
diff changeset
87 textureHeight_(static_cast<float>(alphabet.GetTextureHeight()))
577
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 if (textureWidth_ <= 0 ||
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 textureHeight_ <= 0)
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 width_ = static_cast<float>(box_.GetWidth());
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 height_ = static_cast<float>(box_.GetHeight());
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 // Each character is made of two 2D triangles (= 2 * 3 * 2 = 12)
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 renderingCoords_.reserve(box_.GetCharactersCount() * 12);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 textureCoords_.reserve(box_.GetCharactersCount() * 12);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 alphabet.GetAlphabet().Apply(*this, utf8);
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 const std::vector<float>& OpenGLTextCoordinates::GetRenderingCoords() const
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 assert(renderingCoords_.size() == textureCoords_.size());
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 return renderingCoords_;
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 const std::vector<float>& OpenGLTextCoordinates::GetTextureCoords() const
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 assert(renderingCoords_.size() == textureCoords_.size());
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 return textureCoords_;
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
b098a3aaf694 alphabet of glyphs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }