| 9 | { |
| 10 | |
| 11 | TEST( MRMesh, PointToPlaneAligningTransform1 ) |
| 12 | { |
| 13 | std::vector<Vector3d> pInit, n, n2; |
| 14 | pInit.resize( 10 ); |
| 15 | n.resize( 10 ); |
| 16 | n2.resize( 3 ); |
| 17 | |
| 18 | pInit[0] = { 1.0, 1.0, -5.0 }; n[0] = { 0.0, 0.0, -1.0 }; n2[0] = { 0.1, -0.1, 0.0 }; |
| 19 | pInit[1] = { 14.0, 1.0, 1.0 }; n[1] = { 1.0, 0.1, 1.0 }; n2[1] = { 0.3, 0.0, -0.3 }; |
| 20 | pInit[2] = { 1.0, 14.0, 2.0 }; n[2] = { 0.1, 1.0, 1.2 }; n2[2] = { 0.0, -0.6, 0.5 }; |
| 21 | pInit[3] = { -11.0, 2.0, 3.0 }; n[3] = { -1.0, 0.1, 1.0 }; |
| 22 | pInit[4] = { 1.0, -11.0, 4.0 }; n[4] = { 0.1, -1.1, 1.1 }; |
| 23 | pInit[5] = { 1.0, 2.0, 8.0 }; n[5] = { 0.1, 0.1, 1.0 }; |
| 24 | pInit[6] = { 2.0, 1.0, -5.0 }; n[6] = { 0.1, 0.0, -1.0 }; |
| 25 | pInit[7] = { 15.0, 1.5, 1.0 }; n[7] = { 1.1, 0.1, 1.0 }; |
| 26 | pInit[8] = { 1.5, 15.0, 2.0 }; n[8] = { 0.1, 1.0, 1.2 }; |
| 27 | pInit[9] = { -11.0, 2.5, 3.1 }; n[9] = { -1.1, 0.1, 1.1 }; |
| 28 | |
| 29 | auto preparePt2Pl = [&]( const AffineXf3d & xf ) |
| 30 | { |
| 31 | std::vector<Vector3d> pTransformed( 10 ); |
| 32 | |
| 33 | for( int i = 0; i < 10; i++ ) |
| 34 | pTransformed[i] = xf( pInit[i] ); |
| 35 | for( int i = 0; i < 3; i++ ) |
| 36 | pTransformed[i] += n2[i]; |
| 37 | |
| 38 | PointToPlaneAligningTransform p2pl; |
| 39 | for( int i = 0; i < 10; i++ ) |
| 40 | p2pl.add( pInit[i], pTransformed[i], n[i] ); |
| 41 | p2pl.prepare(); |
| 42 | return p2pl; |
| 43 | }; |
| 44 | |
| 45 | double alpha = 0.15, beta = 0.23, gamma = -0.17; |
| 46 | const Vector3d eulerAngles{ alpha, beta, gamma }; |
| 47 | const auto [e1, e2] = eulerAngles.perpendicular(); |
| 48 | Matrix3d rotationMatrix = Matrix3d::approximateLinearRotationMatrixFromEuler( eulerAngles ); |
| 49 | const Vector3d b( 2., 3., -1. ); |
| 50 | AffineXf3d xf1( rotationMatrix, b ); |
| 51 | |
| 52 | const auto ptp1 = preparePt2Pl( xf1 ); |
| 53 | constexpr double eps = 3e-13; |
| 54 | |
| 55 | { |
| 56 | const auto ammendment = ptp1.calculateAmendment(); |
| 57 | EXPECT_EQ( ammendment.s, 1 ); |
| 58 | auto xf2 = ammendment.linearXf(); |
| 59 | EXPECT_NEAR( ( xf1.A - xf2.A ).norm(), 0., eps ); |
| 60 | EXPECT_NEAR( ( xf1.b - xf2.b ).length(), 0., eps ); |
| 61 | auto shift = ptp1.findBestTranslation( ammendment.a, ammendment.s ); |
| 62 | EXPECT_NEAR( ( xf1.b - shift ).length(), 0., eps ); |
| 63 | } |
| 64 | |
| 65 | { |
| 66 | const auto ammendment = ptp1.calculateAmendmentWithScale(); |
| 67 | EXPECT_NEAR( ammendment.s, 1., 1e-13 ); |
| 68 | auto xf2 = ammendment.linearXf(); |
nothing calls this directly
no test coverage detected