annotate OrthancStone/Sources/Toolbox/GeometryToolbox.h @ 1653:2e3b2ed239b9

Fixed usage of object cookie
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 16 Nov 2020 22:17:01 +0100
parents 8563ea5d8ae4
children 9ac2a65d4172
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1270
2d8ab34c8c91 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
10 * the License, or (at your option) any later version.
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
16 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * <http://www.gnu.org/licenses/>.
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #pragma once
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
25 #include "LinearAlgebra.h"
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 namespace OrthancStone
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 namespace GeometryToolbox
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 void ProjectPointOntoPlane(Vector& result,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 const Vector& point,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 const Vector& planeNormal,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 const Vector& planeOrigin);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
1013
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
36 /*
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
37 Alternated faster implementation (untested yet)
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
38 */
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
39 void ProjectPointOntoPlane2(double& resultX,
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
40 double& resultY,
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
41 double& resultZ,
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
42 const Vector& point,
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
43 const Vector& planeNormal,
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
44 const Vector& planeOrigin);
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
45
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 bool IsParallel(const Vector& u,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 const Vector& v);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 bool IsParallelOrOpposite(bool& isOpposite,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 const Vector& u,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 const Vector& v);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 bool IntersectTwoPlanes(Vector& p,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 Vector& direction,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 const Vector& origin1,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 const Vector& normal1,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 const Vector& origin2,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 const Vector& normal2);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 bool ClipLineToRectangle(double& x1, // Coordinates of the clipped line (out)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 double& y1,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 double& x2,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 double& y2,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 const double ax, // Two points defining the line (in)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 const double ay,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 const double bx,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 const double by,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 const double& xmin, // Coordinates of the rectangle (in)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 const double& ymin,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 const double& xmax,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 const double& ymax);
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
72
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
73 void GetPixelSpacing(double& spacingX,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
74 double& spacingY,
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
75 const Orthanc::DicomMap& dicom);
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
76
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
77 inline double ProjectAlongNormal(const Vector& point,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
78 const Vector& normal)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
79 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
80 return boost::numeric::ublas::inner_prod(point, normal);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
81 }
140
2115530d3703 OrientedBoundingBox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
82
2115530d3703 OrientedBoundingBox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
83 Matrix CreateRotationMatrixAlongX(double a);
2115530d3703 OrientedBoundingBox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
84
2115530d3703 OrientedBoundingBox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
85 Matrix CreateRotationMatrixAlongY(double a);
2115530d3703 OrientedBoundingBox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
86
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
87 Matrix CreateRotationMatrixAlongZ(double a);
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
88
165
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
89 Matrix CreateTranslationMatrix(double dx,
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
90 double dy,
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
91 double dz);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
92
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
93 Matrix CreateScalingMatrix(double sx,
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
94 double sy,
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
95 double sz);
8d50e6be565d LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
96
151
c5044bbfc303 CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 150
diff changeset
97 bool IntersectPlaneAndSegment(Vector& p,
c5044bbfc303 CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 150
diff changeset
98 const Vector& normal,
c5044bbfc303 CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 150
diff changeset
99 double d,
c5044bbfc303 CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 150
diff changeset
100 const Vector& edgeFrom,
c5044bbfc303 CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 150
diff changeset
101 const Vector& edgeTo);
c5044bbfc303 CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 150
diff changeset
102
157
2309e8d86efe IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 156
diff changeset
103 bool IntersectPlaneAndLine(Vector& p,
2309e8d86efe IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 156
diff changeset
104 const Vector& normal,
2309e8d86efe IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 156
diff changeset
105 double d,
2309e8d86efe IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 156
diff changeset
106 const Vector& origin,
2309e8d86efe IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 156
diff changeset
107 const Vector& direction);
2309e8d86efe IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 156
diff changeset
108
189
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
109 void AlignVectorsWithRotation(Matrix& r,
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
110 const Vector& a,
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
111 const Vector& b);
964118e7e6de unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
112
1477
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
113 void ComputeNormalFromCosines(Vector& normal,
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
114 const Vector& cosines);
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
115
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
116 bool ComputeNormal(Vector& normal,
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
117 const Orthanc::DicomMap& dicom);
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
118
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
119 inline float ComputeBilinearInterpolationUnitSquare(float x,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
120 float y,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
121 float f00, // source(0, 0)
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
122 float f01, // source(1, 0)
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
123 float f10, // source(0, 1)
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
124 float f11); // source(1, 1)
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
125
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
126 inline float ComputeTrilinearInterpolationUnitSquare(float x,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
127 float y,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
128 float z,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
129 float f000, // source(0, 0, 0)
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
130 float f001, // source(1, 0, 0)
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
131 float f010, // source(0, 1, 0)
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
132 float f011, // source(1, 1, 0)
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
133 float f100, // source(0, 0, 1)
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
134 float f101, // source(1, 0, 1)
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
135 float f110, // source(0, 1, 1)
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
136 float f111); // source(1, 1, 1)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 };
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
139
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
140
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
141 float OrthancStone::GeometryToolbox::ComputeBilinearInterpolationUnitSquare(float x,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
142 float y,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
143 float f00,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
144 float f01,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
145 float f10,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
146 float f11)
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
147 {
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
148 // This function only works within the unit square
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
149 assert(x >= 0 && y >= 0 && x <= 1 && y <= 1);
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
150
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
151 // https://en.wikipedia.org/wiki/Bilinear_interpolation#Unit_square
175
15d92d93738b fix interpolation with negative coordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
152 return (f00 * (1.0f - x) * (1.0f - y) +
15d92d93738b fix interpolation with negative coordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
153 f01 * x * (1.0f - y) +
15d92d93738b fix interpolation with negative coordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
154 f10 * (1.0f - x) * y +
15d92d93738b fix interpolation with negative coordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 172
diff changeset
155 f11 * x * y);
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
156 }
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
157
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
158
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
159 float OrthancStone::GeometryToolbox::ComputeTrilinearInterpolationUnitSquare(float x,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
160 float y,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
161 float z,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
162 float f000,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
163 float f001,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
164 float f010,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
165 float f011,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
166 float f100,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
167 float f101,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
168 float f110,
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
169 float f111)
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
170 {
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
171 // "In practice, a trilinear interpolation is identical to two
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
172 // bilinear interpolation combined with a linear interpolation"
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
173 // https://en.wikipedia.org/wiki/Trilinear_interpolation#Method
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
174 float a = ComputeBilinearInterpolationUnitSquare(x, y, f000, f001, f010, f011);
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
175 float b = ComputeBilinearInterpolationUnitSquare(x, y, f100, f101, f110, f111);
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
176
177
83200c4d07ca fix interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 175
diff changeset
177 return (1.0f - z) * a + z * b;
144
9b83f30fc1c0 bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
178 }