annotate OrthancStone/Sources/Toolbox/SubvoxelReader.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
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
98da3a8d4820 SubvoxelReader
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
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
98da3a8d4820 SubvoxelReader
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
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
98da3a8d4820 SubvoxelReader
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/>.
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #pragma once
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../Volumes/ImageBuffer3D.h"
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "GeometryToolbox.h"
98da3a8d4820 SubvoxelReader
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>
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <boost/noncopyable.hpp>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <cmath>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 namespace OrthancStone
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 namespace Internals
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 class SubvoxelReaderBase : public boost::noncopyable
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 private:
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 const ImageBuffer3D& source_;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 unsigned int width_;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 unsigned int height_;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 unsigned int depth_;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 public:
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
47 explicit SubvoxelReaderBase(const ImageBuffer3D& source) :
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 source_(source),
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 width_(source.GetWidth()),
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 height_(source.GetHeight()),
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 depth_(source.GetDepth())
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 ORTHANC_FORCE_INLINE
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 const Orthanc::ImageAccessor& GetSource() const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 return source_.GetInternalImage();
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 ORTHANC_FORCE_INLINE
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 unsigned int GetWidth() const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 return width_;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 ORTHANC_FORCE_INLINE
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 unsigned int GetHeight() const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 return height_;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 ORTHANC_FORCE_INLINE
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 unsigned int GetDepth() const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 return depth_;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 ORTHANC_FORCE_INLINE
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 unsigned int ComputeRow(unsigned int y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 unsigned int z) const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
1783
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
83 /**
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
84 * The "(depth_ - 1 - z)" comes from the fact that
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
85 * "ImageBuffer3D" class stores its slices in DECREASING
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
86 * z-order along the normal. This computation makes the
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
87 * "SubvoxelReader" class use the same convention as
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
88 * "ImageBuffer3D::GetVoxelXXX()".
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
89 *
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
90 * WARNING: Until changeset 1782:f053c80ea411, "z" was
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
91 * directly used, causing this class to have a slice order
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
92 * that was reversed between "SubvoxelReader" and
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
93 * "ImageBuffer3D". This notably made
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
94 * "DicomVolumeImageMPRSlicer" and "DicomVolumeImageReslicer"
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
95 * inconsistent in sagittal and coronal views (the texture was
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
96 * flipped along the Y-axis in the canvas).
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
97 **/
75d3e2ab1fe1 BREAKING: SubvoxelReader using the same Z-axis ordering as ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
98 return (depth_ - 1 - z) * height_ + y;
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 };
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 template <Orthanc::PixelFormat Format,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 ImageInterpolation Interpolation>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 class SubvoxelReader;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 template <Orthanc::PixelFormat Format>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 class SubvoxelReader<Format, ImageInterpolation_Nearest> :
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 public Internals::SubvoxelReaderBase
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 public:
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 typedef Orthanc::PixelTraits<Format> Traits;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 typedef typename Traits::PixelType PixelType;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
117 explicit SubvoxelReader(const ImageBuffer3D& source) :
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 SubvoxelReaderBase(source)
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 inline bool GetValue(PixelType& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 float y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 float z) const;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 inline bool GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 float y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 float z) const;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 };
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 template <Orthanc::PixelFormat Format>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 class SubvoxelReader<Format, ImageInterpolation_Bilinear> :
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 public Internals::SubvoxelReaderBase
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 public:
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 typedef Orthanc::PixelTraits<Format> Traits;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 typedef typename Traits::PixelType PixelType;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
142 explicit SubvoxelReader(const ImageBuffer3D& source) :
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 SubvoxelReaderBase(source)
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 inline bool Sample(float& f00,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 float& f01,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 float& f10,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 float& f11,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 unsigned int ux,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 unsigned int uy,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 unsigned int uz) const;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 inline bool GetValue(PixelType& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 float y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 float z) const;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 inline bool GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 float y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 float z) const;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 };
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 template <Orthanc::PixelFormat Format>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 class SubvoxelReader<Format, ImageInterpolation_Trilinear> :
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 public Internals::SubvoxelReaderBase
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 private:
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 SubvoxelReader<Format, ImageInterpolation_Bilinear> bilinear_;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 public:
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 typedef Orthanc::PixelTraits<Format> Traits;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 typedef typename Traits::PixelType PixelType;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
178 explicit SubvoxelReader(const ImageBuffer3D& source) :
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 SubvoxelReaderBase(source),
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 bilinear_(source)
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 inline bool GetValue(PixelType& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 float y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 float z) const;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 inline bool GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 float y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 float z) const;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 };
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 template <Orthanc::PixelFormat Format>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 bool SubvoxelReader<Format, ImageInterpolation_Nearest>::GetValue(PixelType& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 float y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 float z) const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 if (x < 0 ||
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 y < 0 ||
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 z < 0)
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 unsigned int ux = static_cast<unsigned int>(std::floor(x));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 unsigned int uy = static_cast<unsigned int>(std::floor(y));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 unsigned int uz = static_cast<unsigned int>(std::floor(z));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 if (ux < GetWidth() &&
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 uy < GetHeight() &&
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 uz < GetDepth())
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 Orthanc::ImageTraits<Format>::GetPixel(target, GetSource(), ux, ComputeRow(uy, uz));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 return true;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 template <Orthanc::PixelFormat Format>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 bool SubvoxelReader<Format, ImageInterpolation_Nearest>::GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 float y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 float z) const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 PixelType value;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 if (GetValue(value, x, y, z))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 target = Traits::PixelToFloat(value);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 return true;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 template <Orthanc::PixelFormat Format>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 bool SubvoxelReader<Format, ImageInterpolation_Bilinear>::Sample(float& f00,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 float& f01,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 float& f10,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 float& f11,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 unsigned int ux,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 unsigned int uy,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 unsigned int uz) const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 if (ux < GetWidth() &&
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 uy < GetHeight() &&
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 uz < GetDepth())
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 f00 = Orthanc::ImageTraits<Format>::GetFloatPixel(GetSource(), ux, ComputeRow(uy, uz));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 // Pixel is out of the volume
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 if (ux + 1 < GetWidth())
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 f01 = Orthanc::ImageTraits<Format>::GetFloatPixel(GetSource(), ux + 1, ComputeRow(uy, uz));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 f01 = f00;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 if (uy + 1 < GetHeight())
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 f10 = Orthanc::ImageTraits<Format>::GetFloatPixel(GetSource(), ux, ComputeRow(uy + 1, uz));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 f10 = f00;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 if (ux + 1 < GetWidth() &&
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 uy + 1 < GetHeight())
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 f11 = Orthanc::ImageTraits<Format>::GetFloatPixel(GetSource(), ux + 1, ComputeRow(uy + 1, uz));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 f11 = f00;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 return true;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 template <Orthanc::PixelFormat Format>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 bool SubvoxelReader<Format, ImageInterpolation_Bilinear>::GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 float y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 float z) const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 x -= 0.5f;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 y -= 0.5f;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 if (x < 0 ||
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 y < 0 ||
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 z < 0)
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 unsigned int ux = static_cast<unsigned int>(std::floor(x));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 unsigned int uy = static_cast<unsigned int>(std::floor(y));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 unsigned int uz = static_cast<unsigned int>(std::floor(z));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 float f00, f01, f10, f11;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 if (Sample(f00, f01, f10, f11, ux, uy, uz))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 float ax = x - static_cast<float>(ux);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 float ay = y - static_cast<float>(uy);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 target = GeometryToolbox::ComputeBilinearInterpolationUnitSquare(ax, ay, f00, f01, f10, f11);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 return true;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 template <Orthanc::PixelFormat Format>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 bool SubvoxelReader<Format, ImageInterpolation_Bilinear>::GetValue(PixelType& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 float y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 float z) const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 float value;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 if (GetFloatValue(value, x, y, z))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 Traits::FloatToPixel(target, value);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 return true;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 template <Orthanc::PixelFormat Format>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 bool SubvoxelReader<Format, ImageInterpolation_Trilinear>::GetFloatValue(float& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 float y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 float z) const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 x -= 0.5f;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 y -= 0.5f;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 z -= 0.5f;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 if (x < 0 ||
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 y < 0 ||
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 z < 0)
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 unsigned int ux = static_cast<unsigned int>(std::floor(x));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 unsigned int uy = static_cast<unsigned int>(std::floor(y));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 unsigned int uz = static_cast<unsigned int>(std::floor(z));
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 float f000, f001, f010, f011;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 if (bilinear_.Sample(f000, f001, f010, f011, ux, uy, uz))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 const float ax = x - static_cast<float>(ux);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 const float ay = y - static_cast<float>(uy);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 float f100, f101, f110, f111;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 if (bilinear_.Sample(f100, f101, f110, f111, ux, uy, uz + 1))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 const float az = z - static_cast<float>(uz);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 target = GeometryToolbox::ComputeTrilinearInterpolationUnitSquare
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 (ax, ay, az, f000, f001, f010, f011, f100, f101, f110, f111);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 target = GeometryToolbox::ComputeBilinearInterpolationUnitSquare
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 (ax, ay, f000, f001, f010, f011);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 return true;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 template <Orthanc::PixelFormat Format>
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 bool SubvoxelReader<Format, ImageInterpolation_Trilinear>::GetValue(PixelType& target,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 float x,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 float y,
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 float z) const
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 float value;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 if (GetFloatValue(value, x, y, z))
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 Traits::FloatToPixel(target, value);
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 return true;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 else
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 {
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 return false;
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 }
98da3a8d4820 SubvoxelReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 }