Mercurial > hg > orthanc-stone
annotate Framework/Volumes/VolumeReslicer.cpp @ 171:01e32beee56c wasm
upgrade to cairo 1.14.12
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 06 Mar 2018 15:43:57 +0100 |
parents | 0a73d76333db |
children | 316324f42848 |
rev | line source |
---|---|
153
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #include "VolumeReslicer.h" |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 |
159
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
3 #include "../Toolbox/GeometryToolbox.h" |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
4 |
153
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 #include <Core/Logging.h> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 #include <Core/OrthancException.h> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 #include <boost/math/special_functions/round.hpp> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 #if defined(_MSC_VER) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 # define ORTHANC_STONE_FORCE_INLINE __forceinline |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 #elif defined(__GNUC__) || defined(__clang__) || defined(__EMSCRIPTEN__) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # define ORTHANC_STONE_FORCE_INLINE inline __attribute((always_inline)) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 #else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 # error Please support your compiler here |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 #endif |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 namespace OrthancStone |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 // Anonymous namespace to avoid clashes between compilation modules |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 namespace |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 enum TransferFunction |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 TransferFunction_Copy, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 TransferFunction_Float, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 TransferFunction_Linear |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 template <Orthanc::PixelFormat Format> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 struct PixelTraits; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 template <> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 struct PixelTraits<Orthanc::PixelFormat_Grayscale8> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 typedef uint8_t PixelType; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 static void SetOutOfVolume(PixelType& target) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 target = 0; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 static void GetVoxel(PixelType& target, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 const ImageBuffer3D& image, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 unsigned int x, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 unsigned int y, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 unsigned int z) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 assert(x < image.GetWidth() && y < image.GetHeight() && z < image.GetDepth()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 target = image.GetVoxelGrayscale8Unchecked(x, y, z); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 static float GetFloatVoxel(const ImageBuffer3D& image, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 unsigned int x, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 unsigned int y, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 unsigned int z) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 assert(x < image.GetWidth() && y < image.GetHeight() && z < image.GetDepth()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 return static_cast<float>(image.GetVoxelGrayscale8Unchecked(x, y, z)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 template <> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 struct PixelTraits<Orthanc::PixelFormat_Grayscale16> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 typedef uint16_t PixelType; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 static void SetOutOfVolume(PixelType& target) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 target = 0; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 static void GetVoxel(PixelType& target, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 const ImageBuffer3D& image, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 unsigned int x, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 unsigned int y, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 unsigned int z) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 assert(x < image.GetWidth() && y < image.GetHeight() && z < image.GetDepth()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 target = image.GetVoxelGrayscale16Unchecked(x, y, z); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 static float GetFloatVoxel(const ImageBuffer3D& image, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 unsigned int x, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 unsigned int y, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 unsigned int z) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 assert(x < image.GetWidth() && y < image.GetHeight() && z < image.GetDepth()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 return static_cast<float>(image.GetVoxelGrayscale16Unchecked(x, y, z)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 template <> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 struct PixelTraits<Orthanc::PixelFormat_SignedGrayscale16> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 typedef int16_t PixelType; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 static void SetOutOfVolume(PixelType& target) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 target = std::numeric_limits<PixelType>::min(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 static void GetVoxel(PixelType& target, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 const ImageBuffer3D& image, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 unsigned int x, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 unsigned int y, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 unsigned int z) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 assert(x < image.GetWidth() && y < image.GetHeight() && z < image.GetDepth()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 target = image.GetVoxelSignedGrayscale16Unchecked(x, y, z); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 static float GetFloatVoxel(const ImageBuffer3D& image, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 unsigned int x, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 unsigned int y, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 unsigned int z) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 assert(x < image.GetWidth() && y < image.GetHeight() && z < image.GetDepth()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 return static_cast<float>(image.GetVoxelSignedGrayscale16Unchecked(x, y, z)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 template <> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 struct PixelTraits<Orthanc::PixelFormat_BGRA32> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 struct PixelType |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 uint8_t blue_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 uint8_t green_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 uint8_t red_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 uint8_t alpha_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 template <Orthanc::PixelFormat InputFormat, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 Orthanc::PixelFormat OutputFormat> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 class PixelWriter |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 typedef typename PixelTraits<InputFormat>::PixelType InputPixelType; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 typedef PixelTraits<OutputFormat> OutputPixelTraits; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 typedef typename PixelTraits<OutputFormat>::PixelType OutputPixelType; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 private: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 template <typename T> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 static void SetValueInternal(OutputPixelType* pixel, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 const T& value) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 if (value < std::numeric_limits<OutputPixelType>::min()) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 *pixel = std::numeric_limits<OutputPixelType>::min(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 else if (value > std::numeric_limits<OutputPixelType>::max()) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 *pixel = std::numeric_limits<OutputPixelType>::max(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 *pixel = static_cast<OutputPixelType>(value); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 ORTHANC_STONE_FORCE_INLINE |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 void SetFloatValue(OutputPixelType* pixel, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 float value) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 SetValueInternal<float>(pixel, value); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 ORTHANC_STONE_FORCE_INLINE |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 void SetValue(OutputPixelType* pixel, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 const InputPixelType& value) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 SetValueInternal<InputPixelType>(pixel, value); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 template <Orthanc::PixelFormat InputFormat> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 class PixelWriter<InputFormat, Orthanc::PixelFormat_BGRA32> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 typedef typename PixelTraits<InputFormat>::PixelType InputPixelType; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 typedef PixelTraits<Orthanc::PixelFormat_BGRA32> OutputPixelTraits; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 typedef PixelTraits<Orthanc::PixelFormat_BGRA32>::PixelType OutputPixelType; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 private: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 template <typename T> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 static void SetValueInternal(OutputPixelType* pixel, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 const T& value) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 uint8_t v; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 if (value < 0) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 v = 0; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 else if (value >= 255.0f) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 v = 255; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 v = static_cast<uint8_t>(value); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 pixel->blue_ = v; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 pixel->green_ = v; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 pixel->red_ = v; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 pixel->alpha_ = 255; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 ORTHANC_STONE_FORCE_INLINE |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 void SetFloatValue(OutputPixelType* pixel, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 float value) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 SetValueInternal<float>(pixel, value); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 ORTHANC_STONE_FORCE_INLINE |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 void SetValue(OutputPixelType* pixel, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 const InputPixelType& value) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 SetValueInternal<InputPixelType>(pixel, value); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 class VoxelReaderBase |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 protected: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 const ImageBuffer3D& source_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 unsigned int sourceWidth_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
242 unsigned int sourceHeight_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 unsigned int sourceDepth_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 VoxelReaderBase(const ImageBuffer3D& source) : |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 source_(source), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 sourceWidth_(source.GetWidth()), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 sourceHeight_(source.GetHeight()), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 sourceDepth_(source.GetDepth()) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 unsigned int GetSourceWidth() const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 return sourceWidth_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 unsigned int GetSourceHeight() const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 return sourceHeight_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 unsigned int GetSourceDepth() const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 return sourceDepth_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 bool GetNearestCoordinates(unsigned int& sourceX, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 unsigned int& sourceY, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 unsigned int& sourceZ, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 float worldX, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 float worldY, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 float worldZ) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
275 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
276 if (worldX >= 0 && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
277 worldY >= 0 && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 worldZ >= 0) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
279 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
280 sourceX = static_cast<unsigned int>(worldX * static_cast<float>(sourceWidth_)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
281 sourceY = static_cast<unsigned int>(worldY * static_cast<float>(sourceHeight_)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 sourceZ = static_cast<unsigned int>(worldZ * static_cast<float>(sourceDepth_)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
283 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
284 return (sourceX < sourceWidth_ && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 sourceY < sourceHeight_ && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
286 sourceZ < sourceDepth_); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
288 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
289 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
290 return false; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
291 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 template <Orthanc::PixelFormat InputFormat, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 ImageInterpolation Interpolation> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 class VoxelReader; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
300 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
301 template <Orthanc::PixelFormat InputFormat> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
302 class VoxelReader<InputFormat, ImageInterpolation_Nearest> : |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 public VoxelReaderBase |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
304 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
305 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
306 typedef typename PixelTraits<InputFormat>::PixelType InputPixelType; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
308 VoxelReader(const ImageBuffer3D& source) : |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
309 VoxelReaderBase(source) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
310 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
311 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
312 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
313 ORTHANC_STONE_FORCE_INLINE |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 float GetFloatValue(float worldX, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 float worldY, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 float worldZ) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
318 InputPixelType value; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 GetValue(value, worldX, worldY, worldZ); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
320 return static_cast<float>(value); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
321 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
322 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
323 ORTHANC_STONE_FORCE_INLINE |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
324 void GetValue(InputPixelType& target, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
325 float worldX, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
326 float worldY, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
327 float worldZ) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
328 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
329 unsigned int sourceX, sourceY, sourceZ; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
330 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
331 if (GetNearestCoordinates(sourceX, sourceY, sourceZ, worldX, worldY, worldZ)) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
332 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
333 PixelTraits<InputFormat>::GetVoxel(target, source_, sourceX, sourceY, sourceZ); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
334 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
335 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
336 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
337 PixelTraits<InputFormat>::SetOutOfVolume(target); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
338 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
339 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
340 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
341 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
342 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
343 template <Orthanc::PixelFormat InputFormat> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
344 class VoxelReader<InputFormat, ImageInterpolation_Bilinear> : |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
345 public VoxelReaderBase |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
346 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
347 private: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
348 float outOfVolume_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
349 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
350 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
351 VoxelReader(const ImageBuffer3D& source) : |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
352 VoxelReaderBase(source) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
353 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
354 typename PixelTraits<InputFormat>::PixelType value; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
355 PixelTraits<InputFormat>::SetOutOfVolume(value); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
356 outOfVolume_ = static_cast<float>(value); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
357 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
358 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
359 void SampleVoxels(float& f00, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
360 float& f10, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
361 float& f01, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
362 float& f11, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
363 unsigned int sourceX, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
364 unsigned int sourceY, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
365 unsigned int sourceZ) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
366 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
367 f00 = PixelTraits<InputFormat>::GetFloatVoxel(source_, sourceX, sourceY, sourceZ); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
368 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
369 if (sourceX + 1 < sourceWidth_) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
370 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
371 f01 = PixelTraits<InputFormat>::GetFloatVoxel(source_, sourceX + 1, sourceY, sourceZ); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
372 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
373 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
374 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
375 f01 = f00; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
376 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
377 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
378 if (sourceY + 1 < sourceHeight_) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
379 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
380 f10 = PixelTraits<InputFormat>::GetFloatVoxel(source_, sourceX, sourceY + 1, sourceZ); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
381 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
382 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
383 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
384 f10 = f00; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
385 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
386 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
387 if (sourceX + 1 < sourceWidth_ && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
388 sourceY + 1 < sourceHeight_) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
389 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
390 f11 = PixelTraits<InputFormat>::GetFloatVoxel(source_, sourceX + 1, sourceY + 1, sourceZ); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
391 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
392 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
393 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
394 f11 = f00; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
395 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
396 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
397 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
398 float GetOutOfVolume() const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
399 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
400 return outOfVolume_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
401 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
402 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
403 float GetFloatValue(float worldX, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
404 float worldY, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
405 float worldZ) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
406 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
407 unsigned int sourceX, sourceY, sourceZ; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
408 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
409 if (GetNearestCoordinates(sourceX, sourceY, sourceZ, worldX, worldY, worldZ)) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
410 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
411 float f00, f10, f01, f11; |
171
01e32beee56c
upgrade to cairo 1.14.12
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
159
diff
changeset
|
412 SampleVoxels(f00, f10, f01, f11, sourceX, sourceY, sourceZ); |
153
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
413 return GeometryToolbox::ComputeBilinearInterpolation(worldX, worldY, f00, f01, f10, f11); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
414 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
415 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
416 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
417 return outOfVolume_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
418 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
419 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
420 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
421 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
422 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
423 template <Orthanc::PixelFormat InputFormat> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
424 class VoxelReader<InputFormat, ImageInterpolation_Trilinear> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
425 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
426 private: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
427 typedef VoxelReader<InputFormat, ImageInterpolation_Bilinear> Bilinear; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
428 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
429 Bilinear bilinear_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
430 unsigned int sourceDepth_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
431 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
432 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
433 VoxelReader(const ImageBuffer3D& source) : |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
434 bilinear_(source), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
435 sourceDepth_(source.GetDepth()) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
436 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
437 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
438 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
439 float GetFloatValue(float worldX, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
440 float worldY, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
441 float worldZ) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
442 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
443 unsigned int sourceX, sourceY, sourceZ; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
444 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
445 if (bilinear_.GetNearestCoordinates(sourceX, sourceY, sourceZ, worldX, worldY, worldZ)) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
446 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
447 float f000, f010, f001, f011, f100, f110, f101, f111; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
448 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
449 bilinear_.SampleVoxels(f000, f010, f001, f011, sourceX, sourceY, sourceZ); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
450 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
451 if (sourceZ + 1 < sourceDepth_) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
452 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
453 bilinear_.SampleVoxels(f100, f110, f101, f111, sourceX, sourceY, sourceZ + 1); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
454 return GeometryToolbox::ComputeTrilinearInterpolation |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
455 (worldX, worldY, worldZ, f000, f001, f010, f011, f100, f110, f101, f111); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
456 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
457 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
458 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
459 return GeometryToolbox::ComputeBilinearInterpolation(worldX, worldY, f000, f001, f010, f011); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
460 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
461 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
462 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
463 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
464 return bilinear_.GetOutOfVolume(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
465 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
466 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
467 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
468 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
469 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
470 template <typename VoxelReader, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
471 typename PixelWriter, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
472 TransferFunction Function> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
473 class PixelShader; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
474 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
475 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
476 template <typename VoxelReader, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
477 typename PixelWriter> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
478 class PixelShader<VoxelReader, PixelWriter, TransferFunction_Copy> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
479 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
480 private: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
481 VoxelReader reader_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
482 PixelWriter writer_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
483 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
484 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
485 PixelShader(const ImageBuffer3D& image, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
486 float /* scaling */, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
487 float /* offset */) : |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
488 reader_(image) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
489 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
490 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
491 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
492 ORTHANC_STONE_FORCE_INLINE |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
493 void Apply(typename PixelWriter::OutputPixelType* pixel, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
494 float worldX, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
495 float worldY, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
496 float worldZ) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
497 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
498 typename VoxelReader::InputPixelType source; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
499 reader_.GetValue(source, worldX, worldY, worldZ); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
500 writer_.SetValue(pixel, source); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
501 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
502 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
503 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
504 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
505 template <typename VoxelReader, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
506 typename PixelWriter> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
507 class PixelShader<VoxelReader, PixelWriter, TransferFunction_Float> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
508 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
509 private: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
510 VoxelReader reader_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
511 PixelWriter writer_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
512 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
513 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
514 PixelShader(const ImageBuffer3D& image, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
515 float /* scaling */, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
516 float /* offset */) : |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
517 reader_(image) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
518 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
519 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
520 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
521 ORTHANC_STONE_FORCE_INLINE |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
522 void Apply(typename PixelWriter::OutputPixelType* pixel, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
523 float worldX, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
524 float worldY, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
525 float worldZ) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
526 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
527 writer_.SetFloatValue(pixel, reader_.GetFloatValue(worldX, worldY, worldZ)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
528 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
529 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
530 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
531 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
532 template <typename VoxelReader, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
533 typename PixelWriter> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
534 class PixelShader<VoxelReader, PixelWriter, TransferFunction_Linear> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
535 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
536 private: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
537 VoxelReader reader_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
538 PixelWriter writer_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
539 float scaling_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
540 float offset_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
541 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
542 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
543 PixelShader(const ImageBuffer3D& image, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
544 float scaling, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
545 float offset) : |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
546 reader_(image), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
547 scaling_(scaling), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
548 offset_(offset) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
549 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
550 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
551 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
552 ORTHANC_STONE_FORCE_INLINE |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
553 void Apply(typename PixelWriter::OutputPixelType* pixel, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
554 float worldX, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
555 float worldY, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
556 float worldZ) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
557 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
558 writer_.SetFloatValue(pixel, scaling_ * reader_.GetFloatValue(worldX, worldY, worldZ) + offset_); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
559 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
560 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
561 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
562 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
563 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
564 class FastRowIterator : public boost::noncopyable |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
565 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
566 private: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
567 float position_[3]; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
568 float offset_[3]; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
569 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
570 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
571 FastRowIterator(const Orthanc::ImageAccessor& slice, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
572 const Extent2D& extent, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
573 const CoordinateSystem3D& plane, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
574 const OrientedBoundingBox& box, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
575 unsigned int y) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
576 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
577 const double width = static_cast<double>(slice.GetWidth()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
578 const double height = static_cast<double>(slice.GetHeight()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
579 assert(y < height); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
580 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
581 Vector q1 = plane.MapSliceToWorldCoordinates |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
582 (extent.GetX1() + extent.GetWidth() * static_cast<double>(0) / static_cast<double>(width + 1), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
583 extent.GetY1() + extent.GetHeight() * static_cast<double>(y) / static_cast<double>(height + 1)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
584 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
585 Vector q2 = plane.MapSliceToWorldCoordinates |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
586 (extent.GetX1() + extent.GetWidth() * static_cast<double>(width - 1) / static_cast<double>(width + 1), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
587 extent.GetY1() + extent.GetHeight() * static_cast<double>(y) / static_cast<double>(height + 1)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
588 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
589 Vector r1, r2; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
590 box.ToInternalCoordinates(r1, q1); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
591 box.ToInternalCoordinates(r2, q2); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
592 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
593 position_[0] = static_cast<float>(r1[0]); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
594 position_[1] = static_cast<float>(r1[1]); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
595 position_[2] = static_cast<float>(r1[2]); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
596 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
597 Vector tmp = (r2 - r1) / static_cast<double>(width - 1); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
598 offset_[0] = static_cast<float>(tmp[0]); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
599 offset_[1] = static_cast<float>(tmp[1]); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
600 offset_[2] = static_cast<float>(tmp[2]); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
601 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
602 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
603 ORTHANC_STONE_FORCE_INLINE |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
604 void Next() |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
605 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
606 position_[0] += offset_[0]; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
607 position_[1] += offset_[1]; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
608 position_[2] += offset_[2]; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
609 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
610 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
611 ORTHANC_STONE_FORCE_INLINE |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
612 void GetNearestCoordinates(float& x, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
613 float& y, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
614 float& z) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
615 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
616 x = position_[0]; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
617 y = position_[1]; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
618 z = position_[2]; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
619 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
620 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
621 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
622 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
623 class SlowRowIterator : public boost::noncopyable |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
624 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
625 private: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
626 const Orthanc::ImageAccessor& slice_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
627 const Extent2D& extent_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
628 const CoordinateSystem3D& plane_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
629 const OrientedBoundingBox& box_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
630 unsigned int x_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
631 unsigned int y_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
632 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
633 public: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
634 SlowRowIterator(const Orthanc::ImageAccessor& slice, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
635 const Extent2D& extent, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
636 const CoordinateSystem3D& plane, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
637 const OrientedBoundingBox& box, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
638 unsigned int y) : |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
639 slice_(slice), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
640 extent_(extent), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
641 plane_(plane), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
642 box_(box), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
643 x_(0), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
644 y_(y) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
645 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
646 assert(y_ < slice_.GetHeight()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
647 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
648 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
649 void Next() |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
650 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
651 x_++; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
652 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
653 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
654 void GetNearestCoordinates(float& x, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
655 float& y, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
656 float& z) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
657 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
658 assert(x_ < slice_.GetWidth()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
659 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
660 const double width = static_cast<double>(slice_.GetWidth()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
661 const double height = static_cast<double>(slice_.GetHeight()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
662 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
663 Vector q = plane_.MapSliceToWorldCoordinates |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
664 (extent_.GetX1() + extent_.GetWidth() * static_cast<double>(x_) / (width + 1.0), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
665 extent_.GetY1() + extent_.GetHeight() * static_cast<double>(y_) / (height + 1.0)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
666 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
667 Vector r; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
668 box_.ToInternalCoordinates(r, q); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
669 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
670 x = static_cast<float>(r[0]); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
671 y = static_cast<float>(r[1]); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
672 z = static_cast<float>(r[2]); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
673 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
674 }; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
675 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
676 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
677 template <typename RowIterator, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
678 Orthanc::PixelFormat InputFormat, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
679 Orthanc::PixelFormat OutputFormat, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
680 ImageInterpolation Interpolation, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
681 TransferFunction Function> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
682 static void ProcessImage(Orthanc::ImageAccessor& slice, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
683 const Extent2D& extent, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
684 const ImageBuffer3D& source, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
685 const CoordinateSystem3D& plane, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
686 const OrientedBoundingBox& box, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
687 float scaling, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
688 float offset) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
689 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
690 typedef VoxelReader<InputFormat, Interpolation> Reader; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
691 typedef PixelWriter<InputFormat, OutputFormat> Writer; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
692 typedef PixelShader<Reader, Writer, Function> Shader; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
693 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
694 const unsigned int outputWidth = slice.GetWidth(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
695 const unsigned int outputHeight = slice.GetHeight(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
696 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
697 Shader shader(source, scaling, offset); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
698 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
699 for (unsigned int y = 0; y < outputHeight; y++) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
700 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
701 typename Writer::OutputPixelType* p = reinterpret_cast<typename Writer::OutputPixelType*>(slice.GetRow(y)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
702 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
703 RowIterator it(slice, extent, plane, box, y); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
704 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
705 for (unsigned int x = 0; x < outputWidth; x++, p++) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
706 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
707 float worldX, worldY, worldZ; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
708 it.GetNearestCoordinates(worldX, worldY, worldZ); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
709 shader.Apply(p, worldX, worldY, worldZ); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
710 it.Next(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
711 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
712 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
713 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
714 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
715 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
716 template <typename RowIterator, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
717 Orthanc::PixelFormat InputFormat, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
718 Orthanc::PixelFormat OutputFormat> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
719 static void ProcessImage(Orthanc::ImageAccessor& slice, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
720 const Extent2D& extent, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
721 const ImageBuffer3D& source, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
722 const CoordinateSystem3D& plane, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
723 const OrientedBoundingBox& box, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
724 ImageInterpolation interpolation, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
725 bool hasLinearFunction, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
726 float scaling, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
727 float offset) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
728 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
729 if (hasLinearFunction) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
730 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
731 switch (interpolation) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
732 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
733 case ImageInterpolation_Nearest: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
734 ProcessImage<RowIterator, InputFormat, OutputFormat, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
735 ImageInterpolation_Nearest, TransferFunction_Linear> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
736 (slice, extent, source, plane, box, scaling, offset); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
737 break; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
738 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
739 case ImageInterpolation_Bilinear: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
740 ProcessImage<RowIterator, InputFormat, OutputFormat, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
741 ImageInterpolation_Bilinear, TransferFunction_Linear> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
742 (slice, extent, source, plane, box, scaling, offset); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
743 break; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
744 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
745 case ImageInterpolation_Trilinear: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
746 ProcessImage<RowIterator, InputFormat, OutputFormat, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
747 ImageInterpolation_Trilinear, TransferFunction_Linear> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
748 (slice, extent, source, plane, box, scaling, offset); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
749 break; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
750 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
751 default: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
752 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
753 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
754 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
755 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
756 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
757 switch (interpolation) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
758 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
759 case ImageInterpolation_Nearest: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
760 ProcessImage<RowIterator, InputFormat, OutputFormat, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
761 ImageInterpolation_Nearest, TransferFunction_Copy> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
762 (slice, extent, source, plane, box, 0, 0); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
763 break; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
764 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
765 case ImageInterpolation_Bilinear: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
766 ProcessImage<RowIterator, InputFormat, OutputFormat, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
767 ImageInterpolation_Bilinear, TransferFunction_Float> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
768 (slice, extent, source, plane, box, 0, 0); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
769 break; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
770 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
771 case ImageInterpolation_Trilinear: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
772 ProcessImage<RowIterator, InputFormat, OutputFormat, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
773 ImageInterpolation_Trilinear, TransferFunction_Float> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
774 (slice, extent, source, plane, box, 0, 0); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
775 break; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
776 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
777 default: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
778 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
779 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
780 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
781 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
782 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
783 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
784 template <typename RowIterator> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
785 static void ProcessImage(Orthanc::ImageAccessor& slice, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
786 const Extent2D& extent, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
787 const ImageBuffer3D& source, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
788 const CoordinateSystem3D& plane, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
789 const OrientedBoundingBox& box, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
790 ImageInterpolation interpolation, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
791 bool hasLinearFunction, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
792 float scaling, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
793 float offset) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
794 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
795 if (source.GetFormat() == Orthanc::PixelFormat_Grayscale16 && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
796 slice.GetFormat() == Orthanc::PixelFormat_Grayscale8) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
797 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
798 ProcessImage<RowIterator, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
799 Orthanc::PixelFormat_Grayscale16, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
800 Orthanc::PixelFormat_Grayscale8> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
801 (slice, extent, source, plane, box, interpolation, hasLinearFunction, scaling, offset); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
802 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
803 else if (source.GetFormat() == Orthanc::PixelFormat_Grayscale16 && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
804 slice.GetFormat() == Orthanc::PixelFormat_Grayscale16) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
805 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
806 ProcessImage<RowIterator, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
807 Orthanc::PixelFormat_Grayscale16, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
808 Orthanc::PixelFormat_Grayscale16> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
809 (slice, extent, source, plane, box, interpolation, hasLinearFunction, scaling, offset); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
810 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
811 else if (source.GetFormat() == Orthanc::PixelFormat_SignedGrayscale16 && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
812 slice.GetFormat() == Orthanc::PixelFormat_BGRA32) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
813 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
814 ProcessImage<RowIterator, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
815 Orthanc::PixelFormat_SignedGrayscale16, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
816 Orthanc::PixelFormat_BGRA32> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
817 (slice, extent, source, plane, box, interpolation, hasLinearFunction, scaling, offset); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
818 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
819 else if (source.GetFormat() == Orthanc::PixelFormat_Grayscale16 && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
820 slice.GetFormat() == Orthanc::PixelFormat_BGRA32) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
821 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
822 ProcessImage<RowIterator, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
823 Orthanc::PixelFormat_Grayscale16, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
824 Orthanc::PixelFormat_BGRA32> |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
825 (slice, extent, source, plane, box, interpolation, hasLinearFunction, scaling, offset); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
826 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
827 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
828 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
829 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
830 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
831 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
832 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
833 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
834 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
835 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
836 void VolumeReslicer::CheckIterators(const ImageBuffer3D& source, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
837 const CoordinateSystem3D& plane, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
838 const OrientedBoundingBox& box) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
839 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
840 for (unsigned int y = 0; y < slice_->GetHeight(); y++) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
841 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
842 FastRowIterator fast(*slice_, extent_, plane, box, y); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
843 SlowRowIterator slow(*slice_, extent_, plane, box, y); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
844 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
845 for (unsigned int x = 0; x < slice_->GetWidth(); x++) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
846 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
847 float px, py, pz; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
848 fast.GetNearestCoordinates(px, py, pz); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
849 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
850 float qx, qy, qz; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
851 slow.GetNearestCoordinates(qx, qy, qz); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
852 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
853 Vector d; |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
154
diff
changeset
|
854 LinearAlgebra::AssignVector(d, px - qx, py - qy, pz - qz); |
153
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
855 double norm = boost::numeric::ublas::norm_2(d); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
856 if (norm > 0.0001) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
857 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
858 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
859 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
860 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
861 fast.Next(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
862 slow.Next(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
863 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
864 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
865 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
866 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
867 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
868 void VolumeReslicer::Reset() |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
869 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
870 success_ = false; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
871 extent_.Reset(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
872 slice_.reset(NULL); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
873 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
874 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
875 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
876 float VolumeReslicer::GetMinOutputValue() const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
877 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
878 switch (outputFormat_) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
879 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
880 case Orthanc::PixelFormat_Grayscale8: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
881 case Orthanc::PixelFormat_Grayscale16: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
882 case Orthanc::PixelFormat_BGRA32: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
883 return 0.0f; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
884 break; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
885 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
886 default: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
887 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
888 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
889 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
890 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
891 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
892 float VolumeReslicer::GetMaxOutputValue() const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
893 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
894 switch (outputFormat_) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
895 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
896 case Orthanc::PixelFormat_Grayscale8: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
897 case Orthanc::PixelFormat_BGRA32: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
898 return static_cast<float>(std::numeric_limits<uint8_t>::max()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
899 break; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
900 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
901 case Orthanc::PixelFormat_Grayscale16: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
902 return static_cast<float>(std::numeric_limits<uint16_t>::max()); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
903 break; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
904 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
905 default: |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
906 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
907 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
908 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
909 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
910 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
911 VolumeReslicer::VolumeReslicer() : |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
912 outputFormat_(Orthanc::PixelFormat_Grayscale8), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
913 interpolation_(ImageInterpolation_Nearest), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
914 fastMode_(true), |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
915 success_(false) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
916 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
917 ResetLinearFunction(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
918 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
919 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
920 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
921 void VolumeReslicer::GetLinearFunction(float& scaling, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
922 float& offset) const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
923 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
924 if (hasLinearFunction_) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
925 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
926 scaling = scaling_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
927 offset = offset_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
928 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
929 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
930 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
931 scaling = 1.0f; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
932 offset = 0.0f; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
933 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
934 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
935 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
936 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
937 void VolumeReslicer::ResetLinearFunction() |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
938 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
939 Reset(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
940 hasLinearFunction_ = false; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
941 scaling_ = 1.0f; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
942 offset_ = 0.0f; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
943 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
944 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
945 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
946 void VolumeReslicer::SetLinearFunction(float scaling, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
947 float offset) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
948 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
949 Reset(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
950 hasLinearFunction_ = true; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
951 scaling_ = scaling; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
952 offset_ = offset; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
953 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
954 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
955 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
956 void VolumeReslicer::SetWindow(float low, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
957 float high) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
958 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
959 //printf("Range in pixel values: %f->%f\n", low, high); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
960 float scaling = (GetMaxOutputValue() - GetMinOutputValue()) / (high - low); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
961 float offset = GetMinOutputValue() - scaling * low; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
962 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
963 SetLinearFunction(scaling, offset); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
964 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
965 /*float x = scaling_ * low + offset_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
966 float y = scaling_ * high + offset_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
967 printf("%f %f (should be %f->%f)\n", x, y, GetMinOutputValue(), GetMaxOutputValue());*/ |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
968 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
969 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
970 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
971 void VolumeReslicer::FitRange(const ImageBuffer3D& image) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
972 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
973 float minInputValue, maxInputValue; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
974 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
975 if (!image.GetRange(minInputValue, maxInputValue) || |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
976 maxInputValue < 1) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
977 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
978 ResetLinearFunction(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
979 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
980 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
981 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
982 SetWindow(minInputValue, maxInputValue); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
983 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
984 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
985 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
986 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
987 void VolumeReslicer::SetWindowing(ImageWindowing windowing, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
988 const ImageBuffer3D& image, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
989 float rescaleSlope, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
990 float rescaleIntercept) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
991 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
992 if (windowing == ImageWindowing_Custom || |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
993 windowing == ImageWindowing_Default) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
994 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
995 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
996 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
997 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
998 float center, width; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
999 ComputeWindowing(center, width, windowing, 0, 0); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1000 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1001 float a = (center - width / 2.0f - rescaleIntercept) / rescaleSlope; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1002 float b = (center + width / 2.0f - rescaleIntercept) / rescaleSlope; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1003 SetWindow(a, b); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1004 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1005 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1006 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1007 void VolumeReslicer::SetOutputFormat(Orthanc::PixelFormat format) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1008 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1009 if (format != Orthanc::PixelFormat_Grayscale8 && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1010 format != Orthanc::PixelFormat_Grayscale16 && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1011 format != Orthanc::PixelFormat_BGRA32) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1012 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1013 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1014 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1015 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1016 if (hasLinearFunction_) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1017 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1018 LOG(WARNING) << "Calls to VolumeReslicer::SetOutputFormat() should be done before VolumeReslicer::FitRange()"; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1019 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1020 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1021 outputFormat_ = format; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1022 Reset(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1023 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1024 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1025 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1026 void VolumeReslicer::SetInterpolation(ImageInterpolation interpolation) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1027 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1028 if (interpolation != ImageInterpolation_Nearest && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1029 interpolation != ImageInterpolation_Bilinear && |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1030 interpolation != ImageInterpolation_Trilinear) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1031 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1032 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1033 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1034 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1035 interpolation_ = interpolation; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1036 Reset(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1037 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1038 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1039 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1040 const Extent2D& VolumeReslicer::GetOutputExtent() const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1041 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1042 if (success_) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1043 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1044 return extent_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1045 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1046 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1047 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1048 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1049 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1050 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1051 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1052 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1053 const Orthanc::ImageAccessor& VolumeReslicer::GetOutputSlice() const |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1054 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1055 if (success_) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1056 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1057 assert(slice_.get() != NULL); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1058 return *slice_; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1059 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1060 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1061 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1062 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1063 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1064 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1065 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1066 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1067 Orthanc::ImageAccessor* VolumeReslicer::ReleaseOutputSlice() |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1068 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1069 if (success_) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1070 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1071 assert(slice_.get() != NULL); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1072 success_ = false; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1073 return slice_.release(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1074 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1075 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1076 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1077 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1078 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1079 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1080 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1081 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1082 void VolumeReslicer::Apply(const ImageBuffer3D& source, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1083 const CoordinateSystem3D& plane) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1084 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1085 // Choose the default voxel size as the finest voxel dimension |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1086 // of the source volumetric image |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1087 const OrthancStone::Vector dim = source.GetVoxelDimensions(OrthancStone::VolumeProjection_Axial); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1088 double voxelSize = dim[0]; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1089 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1090 if (dim[1] < voxelSize) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1091 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1092 voxelSize = dim[1]; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1093 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1094 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1095 if (dim[2] < voxelSize) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1096 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1097 voxelSize = dim[2]; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1098 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1099 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1100 if (voxelSize <= 0) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1101 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1102 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1103 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1104 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1105 Apply(source, plane, voxelSize); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1106 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1107 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1108 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1109 void VolumeReslicer::Apply(const ImageBuffer3D& source, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1110 const CoordinateSystem3D& plane, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1111 double voxelSize) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1112 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1113 Reset(); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1114 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1115 // Firstly, compute the intersection of the source volumetric |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1116 // image with the reslicing plane. This leads to a polygon with 3 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1117 // to 6 vertices. We compute the extent of the intersection |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1118 // polygon, with respect to the coordinate system of the reslicing |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1119 // plane. |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1120 OrientedBoundingBox box(source); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1121 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1122 if (!box.ComputeExtent(extent_, plane)) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1123 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1124 // The plane does not intersect with the bounding box of the volume |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1125 slice_.reset(new Orthanc::Image(outputFormat_, 0, 0, false)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1126 success_ = true; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1127 return; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1128 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1129 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1130 // Secondly, the extent together with the voxel size gives the |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1131 // size of the output image |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1132 unsigned int width = boost::math::round(extent_.GetWidth() / voxelSize); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1133 unsigned int height = boost::math::round(extent_.GetHeight() / voxelSize); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1134 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1135 slice_.reset(new Orthanc::Image(outputFormat_, width, height, false)); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1136 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1137 //CheckIterators(source, plane, box); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1138 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1139 if (fastMode_) |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1140 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1141 ProcessImage<FastRowIterator>(*slice_, extent_, source, plane, box, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1142 interpolation_, hasLinearFunction_, scaling_, offset_); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1143 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1144 else |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1145 { |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1146 ProcessImage<SlowRowIterator>(*slice_, extent_, source, plane, box, |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1147 interpolation_, hasLinearFunction_, scaling_, offset_); |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1148 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1149 |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1150 success_ = true; |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1151 } |
ae531ab5dcd9
new class: VolumeReslicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1152 } |