annotate OrthancStone/Sources/Toolbox/SubpixelReader.h @ 2123:538c7b7c6e46 deep-learning

integration mainline->deep-learning
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 22 Mar 2024 16:11:42 +0100
parents c23eef785569
children 16c01cc201e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2114
c23eef785569 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2077
diff changeset
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium
c23eef785569 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2077
diff changeset
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
2cbfb08f3a95 ImageGeometry.cpp
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
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
2cbfb08f3a95 ImageGeometry.cpp
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: 1571
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/>.
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #pragma once
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
194
7a031ac16b2d rename Enumerations.h to StoneEnumerations.h to avoid clashes with Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 183
diff changeset
26 #include "../StoneEnumerations.h"
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "GeometryToolbox.h"
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
29 #include <Images/ImageTraits.h>
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <boost/noncopyable.hpp>
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <cmath>
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 namespace OrthancStone
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 namespace Internals
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 class SubpixelReaderBase : public boost::noncopyable
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 private:
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 const Orthanc::ImageAccessor& source_;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 unsigned int width_;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 unsigned int height_;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 public:
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
46 explicit SubpixelReaderBase(const Orthanc::ImageAccessor& source) :
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 source_(source),
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 width_(source.GetWidth()),
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 height_(source.GetHeight())
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 ORTHANC_FORCE_INLINE
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 const Orthanc::ImageAccessor& GetSource() const
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 return source_;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 ORTHANC_FORCE_INLINE
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 unsigned int GetWidth() const
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 return width_;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 ORTHANC_FORCE_INLINE
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 unsigned int GetHeight() const
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 return height_;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 };
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 template <Orthanc::PixelFormat Format,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 ImageInterpolation Interpolation>
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 class SubpixelReader;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 template <Orthanc::PixelFormat Format>
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 class SubpixelReader<Format, ImageInterpolation_Nearest> :
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 public Internals::SubpixelReaderBase
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 public:
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 typedef Orthanc::PixelTraits<Format> Traits;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 typedef typename Traits::PixelType PixelType;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
87 explicit SubpixelReader(const Orthanc::ImageAccessor& source) :
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 SubpixelReaderBase(source)
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 inline bool GetValue(PixelType& target,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 float x,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 float y) const;
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
95
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
96 inline bool GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
97 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
98 float y) const;
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 };
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
100
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 template <Orthanc::PixelFormat Format>
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 class SubpixelReader<Format, ImageInterpolation_Bilinear> :
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 public Internals::SubpixelReaderBase
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 public:
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 typedef Orthanc::PixelTraits<Format> Traits;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 typedef typename Traits::PixelType PixelType;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
111 explicit SubpixelReader(const Orthanc::ImageAccessor& source) :
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 SubpixelReaderBase(source)
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
116 inline bool GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
117 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
118 float y) const;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
119
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 inline bool GetValue(PixelType& target,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 float x,
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
122 float y) const;
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 };
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 template <Orthanc::PixelFormat Format>
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 bool SubpixelReader<Format, ImageInterpolation_Nearest>::GetValue(PixelType& target,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 float x,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 float y) const
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 if (x < 0 ||
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 y < 0)
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 return false;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 unsigned int ux = static_cast<unsigned int>(std::floor(x));
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 unsigned int uy = static_cast<unsigned int>(std::floor(y));
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 if (ux < GetWidth() &&
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 uy < GetHeight())
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 Orthanc::ImageTraits<Format>::GetPixel(target, GetSource(), ux, uy);
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 return true;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 return false;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 template <Orthanc::PixelFormat Format>
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
158 bool SubpixelReader<Format, ImageInterpolation_Nearest>::GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
159 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
160 float y) const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
161 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
162 PixelType value;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
163
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
164 if (GetValue(value, x, y))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
165 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
166 target = Traits::PixelToFloat(value);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
167 return true;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
168 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
169 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
170 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
171 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
172 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
173 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
174
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
175
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
176
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
177 template <Orthanc::PixelFormat Format>
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 bool SubpixelReader<Format, ImageInterpolation_Bilinear>::GetValue(PixelType& target,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 float x,
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
180 float y) const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
181 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
182 float value;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
184 if (GetFloatValue(value, x, y))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
185 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
186 Traits::FloatToPixel(target, value);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
187 return true;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
188 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
189 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
190 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
191 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
192 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
193 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
194
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
195
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
196
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
197 template <Orthanc::PixelFormat Format>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
198 bool SubpixelReader<Format, ImageInterpolation_Bilinear>::GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
199 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
200 float y) const
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 x -= 0.5f;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 y -= 0.5f;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 if (x < 0 ||
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 y < 0)
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 return false;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 unsigned int ux = static_cast<unsigned int>(std::floor(x));
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 unsigned int uy = static_cast<unsigned int>(std::floor(y));
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 float f00, f01, f10, f11;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 if (ux < GetWidth() &&
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 uy < GetHeight())
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 f00 = Orthanc::ImageTraits<Format>::GetFloatPixel(GetSource(), ux, uy);
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 return false;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 if (ux + 1 < GetWidth())
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 f01 = Orthanc::ImageTraits<Format>::GetFloatPixel(GetSource(), ux + 1, uy);
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 f01 = f00;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 if (uy + 1 < GetHeight())
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 f10 = Orthanc::ImageTraits<Format>::GetFloatPixel(GetSource(), ux, uy + 1);
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 f10 = f00;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 if (ux + 1 < GetWidth() &&
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 uy + 1 < GetHeight())
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 f11 = Orthanc::ImageTraits<Format>::GetFloatPixel(GetSource(), ux + 1, uy + 1);
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 f11 = f00;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 float ax = x - static_cast<float>(ux);
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 float ay = y - static_cast<float>(uy);
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
257 target = GeometryToolbox::ComputeBilinearInterpolationUnitSquare(ax, ay, f00, f01, f10, f11);
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 return true;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 }