Mercurial > hg > orthanc-stone
comparison UnitTestsSources/UnitTestsMain.cpp @ 1650:af312e145980
more tests for CoordinateSystem3D
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 13 Nov 2020 10:44:11 +0100 |
parents | 4a43106bc122 |
children | f62f685e0eb2 |
comparison
equal
deleted
inserted
replaced
1649:d77618883551 | 1650:af312e145980 |
---|---|
41 TEST(GeometryToolbox, Interpolation) | 41 TEST(GeometryToolbox, Interpolation) |
42 { | 42 { |
43 using namespace OrthancStone::GeometryToolbox; | 43 using namespace OrthancStone::GeometryToolbox; |
44 | 44 |
45 // https://en.wikipedia.org/wiki/Bilinear_interpolation#Application_in_image_processing | 45 // https://en.wikipedia.org/wiki/Bilinear_interpolation#Application_in_image_processing |
46 ASSERT_FLOAT_EQ(146.1f, ComputeBilinearInterpolationUnitSquare(0.5f, 0.2f, 91, 210, 162, 95)); | 46 ASSERT_DOUBLE_EQ(146.1f, ComputeBilinearInterpolationUnitSquare(0.5f, 0.2f, 91, 210, 162, 95)); |
47 | 47 |
48 ASSERT_FLOAT_EQ(91, ComputeBilinearInterpolationUnitSquare(0, 0, 91, 210, 162, 95)); | 48 ASSERT_DOUBLE_EQ(91, ComputeBilinearInterpolationUnitSquare(0, 0, 91, 210, 162, 95)); |
49 ASSERT_FLOAT_EQ(210, ComputeBilinearInterpolationUnitSquare(1, 0, 91, 210, 162, 95)); | 49 ASSERT_DOUBLE_EQ(210, ComputeBilinearInterpolationUnitSquare(1, 0, 91, 210, 162, 95)); |
50 ASSERT_FLOAT_EQ(162, ComputeBilinearInterpolationUnitSquare(0, 1, 91, 210, 162, 95)); | 50 ASSERT_DOUBLE_EQ(162, ComputeBilinearInterpolationUnitSquare(0, 1, 91, 210, 162, 95)); |
51 ASSERT_FLOAT_EQ(95, ComputeBilinearInterpolationUnitSquare(1, 1, 91, 210, 162, 95)); | 51 ASSERT_DOUBLE_EQ(95, ComputeBilinearInterpolationUnitSquare(1, 1, 91, 210, 162, 95)); |
52 | 52 |
53 ASSERT_FLOAT_EQ(123.35f, ComputeTrilinearInterpolationUnitSquare | 53 ASSERT_DOUBLE_EQ(123.35f, ComputeTrilinearInterpolationUnitSquare |
54 (0.5f, 0.2f, 0.7f, | 54 (0.5f, 0.2f, 0.7f, |
55 91, 210, 162, 95, | 55 91, 210, 162, 95, |
56 51, 190, 80, 92)); | 56 51, 190, 80, 92)); |
57 | 57 |
58 ASSERT_FLOAT_EQ(ComputeBilinearInterpolationUnitSquare(0.5f, 0.2f, 91, 210, 162, 95), | 58 ASSERT_DOUBLE_EQ(ComputeBilinearInterpolationUnitSquare(0.5f, 0.2f, 91, 210, 162, 95), |
59 ComputeTrilinearInterpolationUnitSquare(0.5f, 0.2f, 0, | 59 ComputeTrilinearInterpolationUnitSquare(0.5f, 0.2f, 0, |
60 91, 210, 162, 95, | 60 91, 210, 162, 95, |
61 51, 190, 80, 92)); | 61 51, 190, 80, 92)); |
62 | 62 |
63 ASSERT_FLOAT_EQ(ComputeBilinearInterpolationUnitSquare(0.5f, 0.2f, 51, 190, 80, 92), | 63 ASSERT_DOUBLE_EQ(ComputeBilinearInterpolationUnitSquare(0.5f, 0.2f, 51, 190, 80, 92), |
64 ComputeTrilinearInterpolationUnitSquare(0.5f, 0.2f, 1, | 64 ComputeTrilinearInterpolationUnitSquare(0.5f, 0.2f, 1, |
65 91, 210, 162, 95, | 65 91, 210, 162, 95, |
66 51, 190, 80, 92)); | 66 51, 190, 80, 92)); |
67 } | 67 } |
68 | 68 |
879 } | 879 } |
880 | 880 |
881 | 881 |
882 TEST(CoordinateSystem3D, Basic) | 882 TEST(CoordinateSystem3D, Basic) |
883 { | 883 { |
884 { | 884 using namespace OrthancStone; |
885 OrthancStone::CoordinateSystem3D c; | 885 |
886 { | |
887 CoordinateSystem3D c; | |
886 ASSERT_FALSE(c.IsValid()); | 888 ASSERT_FALSE(c.IsValid()); |
887 ASSERT_FLOAT_EQ(c.GetNormal()[0], 0); | 889 ASSERT_DOUBLE_EQ(c.GetNormal()[0], 0); |
888 ASSERT_FLOAT_EQ(c.GetNormal()[1], 0); | 890 ASSERT_DOUBLE_EQ(c.GetNormal()[1], 0); |
889 ASSERT_FLOAT_EQ(c.GetNormal()[2], 1); | 891 ASSERT_DOUBLE_EQ(c.GetNormal()[2], 1); |
890 | 892 |
891 ASSERT_FLOAT_EQ(0, c.ComputeDistance(OrthancStone::LinearAlgebra::CreateVector(0, 0, 0))); | 893 ASSERT_DOUBLE_EQ(0, c.ComputeDistance(LinearAlgebra::CreateVector(0, 0, 0))); |
892 ASSERT_FLOAT_EQ(0, c.ComputeDistance(OrthancStone::LinearAlgebra::CreateVector(5, 0, 0))); | 894 ASSERT_DOUBLE_EQ(0, c.ComputeDistance(LinearAlgebra::CreateVector(5, 0, 0))); |
893 ASSERT_FLOAT_EQ(0, c.ComputeDistance(OrthancStone::LinearAlgebra::CreateVector(0, 5, 0))); | 895 ASSERT_DOUBLE_EQ(0, c.ComputeDistance(LinearAlgebra::CreateVector(0, 5, 0))); |
894 ASSERT_FLOAT_EQ(5, c.ComputeDistance(OrthancStone::LinearAlgebra::CreateVector(0, 0, 5))); | 896 ASSERT_DOUBLE_EQ(5, c.ComputeDistance(LinearAlgebra::CreateVector(0, 0, 5))); |
895 } | 897 } |
896 | 898 |
897 { | 899 { |
898 OrthancStone::CoordinateSystem3D c("nope1", "nope2"); | 900 CoordinateSystem3D c("nope1", "nope2"); |
899 ASSERT_FALSE(c.IsValid()); | 901 ASSERT_FALSE(c.IsValid()); |
900 ASSERT_FLOAT_EQ(c.GetNormal()[0], 0); | 902 ASSERT_DOUBLE_EQ(c.GetNormal()[0], 0); |
901 ASSERT_FLOAT_EQ(c.GetNormal()[1], 0); | 903 ASSERT_DOUBLE_EQ(c.GetNormal()[1], 0); |
902 ASSERT_FLOAT_EQ(c.GetNormal()[2], 1); | 904 ASSERT_DOUBLE_EQ(c.GetNormal()[2], 1); |
903 } | 905 } |
904 | 906 |
905 { | 907 { |
906 // https://www.vedantu.com/maths/perpendicular-distance-of-a-point-from-a-plane | 908 // https://www.vedantu.com/maths/perpendicular-distance-of-a-point-from-a-plane |
907 OrthancStone::CoordinateSystem3D c = | 909 CoordinateSystem3D c = CoordinateSystem3D::CreateFromPlaneGeneralForm(2, 4, -4, -6); |
908 OrthancStone::CoordinateSystem3D::CreateFromPlaneGeneralForm(2, 4, -4, -6); | 910 ASSERT_DOUBLE_EQ(3, c.ComputeDistance(LinearAlgebra::CreateVector(0, 3, 6))); |
909 ASSERT_FLOAT_EQ(3, c.ComputeDistance(OrthancStone::LinearAlgebra::CreateVector(0, 3, 6))); | 911 } |
912 | |
913 { | |
914 // https://mathinsight.org/distance_point_plane_examples | |
915 CoordinateSystem3D c = CoordinateSystem3D::CreateFromPlaneGeneralForm(2, -2, 5, 8); | |
916 ASSERT_DOUBLE_EQ(39.0 / sqrt(33.0), c.ComputeDistance(LinearAlgebra::CreateVector(4, -4, 3))); | |
917 } | |
918 | |
919 { | |
920 // https://www.ck12.org/calculus/distance-between-a-point-and-a-plane/lesson/Distance-Between-a-Point-and-a-Plane-MAT-ALY/ | |
921 const Vector a = LinearAlgebra::CreateVector(3, 6, 9); | |
922 const Vector b = LinearAlgebra::CreateVector(9, 6, 3); | |
923 const Vector c = LinearAlgebra::CreateVector(6, -9, 9); | |
924 CoordinateSystem3D d = CoordinateSystem3D::CreateFromThreePoints(a, b, c); | |
925 ASSERT_DOUBLE_EQ(0, d.ComputeDistance(a)); | |
926 ASSERT_DOUBLE_EQ(0, d.ComputeDistance(b)); | |
927 ASSERT_DOUBLE_EQ(0, d.ComputeDistance(c)); | |
928 } | |
929 | |
930 { | |
931 // https://tutorial.math.lamar.edu/classes/calcii/eqnsofplanes.aspx | |
932 const Vector a = LinearAlgebra::CreateVector(1, -2, 0); | |
933 const Vector b = LinearAlgebra::CreateVector(3, 1, 4); | |
934 const Vector c = LinearAlgebra::CreateVector(0, -1, 2); | |
935 CoordinateSystem3D d = CoordinateSystem3D::CreateFromThreePoints(a, b, c); | |
936 double r = d.GetNormal() [0] / 2.0; | |
937 ASSERT_DOUBLE_EQ(-8 * r, d.GetNormal() [1]); | |
938 ASSERT_DOUBLE_EQ(5 * r, d.GetNormal() [2]); | |
910 } | 939 } |
911 } | 940 } |
912 | 941 |
913 | 942 |
914 int main(int argc, char **argv) | 943 int main(int argc, char **argv) |