Skip to content

Commit

Permalink
Merge pull request #272 from simonpierredeschenes/rigid_transformatio…
Browse files Browse the repository at this point in the history
…n_bugfix

 Add error message when non-rigid transformations are detected
  • Loading branch information
simonpierredeschenes authored Sep 7, 2018
2 parents e59f92b + 83f12da commit 441e24c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
6 changes: 6 additions & 0 deletions pointmatcher/TransformationsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,14 @@ typename PointMatcher<T>::TransformationParameters TransformationsImpl<T>::Rigid
}
else if(ortho.cols() == 3)
{
const T epsilon = 0.001;

// R = [ a b]
// [-b a]
if(anyabs(parameters(0,0) - parameters(1,1)) > epsilon || anyabs(parameters(1,0) + parameters(0,1)) > epsilon)
{
throw TransformationError("RigidTransformation: Error, only proper rigid transformations are supported.");
}

// mean of a and b
T a = (parameters(0,0) + parameters(1,1))/2;
Expand Down
23 changes: 16 additions & 7 deletions utest/ui/Transformations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,29 @@ TEST(Transformation, RigidTransformation)

//-------------------------------------
// Construct a 2D non-orthogonal matrix
PM::Matrix T_2D = PM::Matrix::Identity(3,3);
T_2D(1,0) = 8.99;
T_2D(0,1) = 4.03;
PM::Matrix T_2D_non_ortho = PM::Matrix::Identity(3,3);
T_2D_non_ortho(0,0) = 0.8;
T_2D_non_ortho(0,1) = -0.5;
T_2D_non_ortho(1,0) = 0.5;
T_2D_non_ortho(1,1) = 0.8;

EXPECT_FALSE(rigidTrans->checkParameters(T_2D));
EXPECT_FALSE(rigidTrans->checkParameters(T_2D_non_ortho));

EXPECT_THROW(rigidTrans->compute(data2D, T_2D), TransformationError);
EXPECT_THROW(rigidTrans->compute(data2D, T_2D_non_ortho), TransformationError);

// Check stability over iterations
for(int i = 0; i < 10; i++)
{
T_2D = rigidTrans->correctParameters(T_2D);
EXPECT_TRUE(rigidTrans->checkParameters(T_2D));
T_2D_non_ortho = rigidTrans->correctParameters(T_2D_non_ortho);
EXPECT_TRUE(rigidTrans->checkParameters(T_2D_non_ortho));
}

//-------------------------------------
// Construct a 2D reflection matrix
PM::Matrix T_2D_reflection = PM::Matrix::Identity(3,3);
T_2D_reflection(1,1) = -1;

EXPECT_THROW(rigidTrans->correctParameters(T_2D_reflection), TransformationError);

delete rigidTrans;
}

0 comments on commit 441e24c

Please sign in to comment.