annotate OrthancStone/Sources/Toolbox/SubpixelReader.h @ 1817:385c268e8b56

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 May 2021 19:51:45 +0200
parents 9ac2a65d4172
children 3889ae96d2e9
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
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
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
2cbfb08f3a95 ImageGeometry.cpp
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: 1596
diff changeset
8 * 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
9 * as published by the Free Software Foundation, either version 3 of
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * 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
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: 1596
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: 1596
diff changeset
15 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
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: 1596
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: 1596
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: 1596
diff changeset
19 * <http://www.gnu.org/licenses/>.
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
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 #pragma once
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
194
7a031ac16b2d rename Enumerations.h to StoneEnumerations.h to avoid clashes with Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 183
diff changeset
25 #include "../StoneEnumerations.h"
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "GeometryToolbox.h"
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
28 #include <Images/ImageTraits.h>
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include <boost/noncopyable.hpp>
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <cmath>
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace OrthancStone
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace Internals
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 class SubpixelReaderBase : public boost::noncopyable
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 private:
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 const Orthanc::ImageAccessor& source_;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 unsigned int width_;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 unsigned int height_;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 public:
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
45 explicit SubpixelReaderBase(const Orthanc::ImageAccessor& source) :
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 source_(source),
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 width_(source.GetWidth()),
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 height_(source.GetHeight())
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
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 ORTHANC_FORCE_INLINE
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 const Orthanc::ImageAccessor& GetSource() const
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 return source_;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
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 ORTHANC_FORCE_INLINE
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 unsigned int GetWidth() const
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 return width_;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
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 ORTHANC_FORCE_INLINE
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 unsigned int GetHeight() const
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 return height_;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
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 template <Orthanc::PixelFormat Format,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 ImageInterpolation Interpolation>
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 class SubpixelReader;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
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 template <Orthanc::PixelFormat Format>
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 class SubpixelReader<Format, ImageInterpolation_Nearest> :
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 public Internals::SubpixelReaderBase
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 public:
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 typedef Orthanc::PixelTraits<Format> Traits;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 typedef typename Traits::PixelType PixelType;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
86 explicit SubpixelReader(const Orthanc::ImageAccessor& source) :
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 SubpixelReaderBase(source)
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
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 inline bool GetValue(PixelType& target,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 float x,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 float y) const;
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
94
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
95 inline bool GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
96 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
97 float y) const;
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 };
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
99
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
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 template <Orthanc::PixelFormat Format>
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 class SubpixelReader<Format, ImageInterpolation_Bilinear> :
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 public Internals::SubpixelReaderBase
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 public:
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 typedef Orthanc::PixelTraits<Format> Traits;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 typedef typename Traits::PixelType PixelType;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
110 explicit SubpixelReader(const Orthanc::ImageAccessor& source) :
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 SubpixelReaderBase(source)
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
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
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
115 inline bool GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
116 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
117 float y) const;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
118
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 inline bool GetValue(PixelType& target,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 float x,
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
121 float y) const;
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 };
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 template <Orthanc::PixelFormat Format>
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 bool SubpixelReader<Format, ImageInterpolation_Nearest>::GetValue(PixelType& target,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 float x,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 float y) const
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 if (x < 0 ||
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 y < 0)
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 return false;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 unsigned int ux = static_cast<unsigned int>(std::floor(x));
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 unsigned int uy = static_cast<unsigned int>(std::floor(y));
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 if (ux < GetWidth() &&
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 uy < GetHeight())
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 Orthanc::ImageTraits<Format>::GetPixel(target, GetSource(), ux, uy);
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 return true;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 return false;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
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 template <Orthanc::PixelFormat Format>
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
157 bool SubpixelReader<Format, ImageInterpolation_Nearest>::GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
158 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
159 float y) const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
160 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
161 PixelType value;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
162
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
163 if (GetValue(value, x, y))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
164 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
165 target = Traits::PixelToFloat(value);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
166 return true;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
167 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
168 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
169 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
170 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
171 }
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 template <Orthanc::PixelFormat Format>
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 bool SubpixelReader<Format, ImageInterpolation_Bilinear>::GetValue(PixelType& target,
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 float x,
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
179 float y) const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
180 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
181 float value;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
182
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
183 if (GetFloatValue(value, x, y))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
184 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
185 Traits::FloatToPixel(target, value);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
186 return true;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
187 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
188 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
189 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
190 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
191 }
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 template <Orthanc::PixelFormat Format>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
197 bool SubpixelReader<Format, ImageInterpolation_Bilinear>::GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
198 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
199 float y) const
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 x -= 0.5f;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 y -= 0.5f;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 if (x < 0 ||
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 y < 0)
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 return false;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 unsigned int ux = static_cast<unsigned int>(std::floor(x));
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 unsigned int uy = static_cast<unsigned int>(std::floor(y));
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 float f00, f01, f10, f11;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 if (ux < GetWidth() &&
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 uy < GetHeight())
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 f00 = Orthanc::ImageTraits<Format>::GetFloatPixel(GetSource(), ux, uy);
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 return false;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 }
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 if (ux + 1 < GetWidth())
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 f01 = Orthanc::ImageTraits<Format>::GetFloatPixel(GetSource(), ux + 1, uy);
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 f01 = f00;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
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 if (uy + 1 < GetHeight())
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 f10 = Orthanc::ImageTraits<Format>::GetFloatPixel(GetSource(), ux, uy + 1);
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 f10 = f00;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 }
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 if (ux + 1 < GetWidth() &&
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 uy + 1 < GetHeight())
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 f11 = Orthanc::ImageTraits<Format>::GetFloatPixel(GetSource(), ux + 1, uy + 1);
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 }
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 else
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 {
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 f11 = f00;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 }
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 float ax = x - static_cast<float>(ux);
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 float ay = y - static_cast<float>(uy);
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 182
diff changeset
256 target = GeometryToolbox::ComputeBilinearInterpolationUnitSquare(ax, ay, f00, f01, f10, f11);
182
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 return true;
2cbfb08f3a95 ImageGeometry.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 }
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 }