test_basics.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2019, Bielefeld University
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Bielefeld University nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #include <Eigen/Core>
36 #include <Eigen/Geometry>
38 #include <gtest/gtest.h>
39 
41 {
42  Eigen::Isometry3d t(Eigen::AngleAxisd(0.42, Eigen::Vector3d(1, 1, 1).normalized()));
43  ASSERT_TRUE(::checkIsometry(t));
44 
45  const Eigen::Vector3d oldDiagonal = t.linear().diagonal();
46  t.linear() = t.linear() * Eigen::DiagonalMatrix<double, 3, 3>(1.0, 2.0, 3.0);
47  ASSERT_FALSE(::checkIsometry(t));
48 
49  t.matrix().row(3) = Eigen::Vector4d(1e-6, 1e-6, 1e-6, 1 - 1e-6);
50  ASSERT_FALSE(::checkIsometry(t, CHECK_ISOMETRY_PRECISION));
51 
52  t.linear().diagonal() = oldDiagonal;
53  ASSERT_TRUE(::checkIsometry(t, 1e-0, false));
54  ASSERT_FALSE(::checkIsometry(t, 1e-1));
55  ASSERT_FALSE(::checkIsometry(t, 1e-2, false));
56 
57  std::cerr.flush();
58 }
59 
60 TEST(Utils, assertIsometry)
61 {
62  Eigen::Isometry3d t(Eigen::AngleAxisd(0.42, Eigen::Vector3d(1, 1, 1).normalized()));
63  ASSERT_ISOMETRY(t);
64 
65  t.linear() = t.linear() * Eigen::DiagonalMatrix<double, 3, 3>(1.0, 2.0, 3.0);
66 #ifdef NDEBUG
67  ASSERT_ISOMETRY(t) // noop in release mode
68 #else
69  ASSERT_DEATH(ASSERT_ISOMETRY(t), "Invalid isometry transform");
70 #endif
71 
72  t.matrix().row(3) = Eigen::Vector4d(1e-6, 1e-6, 1e-6, 1 - 1e-6);
73 #ifdef NDEBUG
74  ASSERT_ISOMETRY(t) // noop in release mode
75 #else
76  ASSERT_DEATH(ASSERT_ISOMETRY(t), "Invalid isometry transform");
77 #endif
78 
79  std::cerr.flush();
80 }
81 
82 int main(int argc, char** argv)
83 {
84  testing::InitGoogleTest(&argc, argv);
85  return RUN_ALL_TESTS();
86 }
bool checkIsometry(const Eigen::Isometry3d &transform, const double precision=CHECK_ISOMETRY_PRECISION, const bool printError=true)
Check whether the given transform is really (mathematically) an isometry.
int main(int argc, char **argv)
Definition: test_basics.cpp:82
#define ASSERT_ISOMETRY(transform)
Assert that the given transform is an isometry.
#define CHECK_ISOMETRY_PRECISION
This file provides functions and macros that can be used to verify that an Eigen::Isometry3d is reall...
TEST(Utils, checkIsometry)
Definition: test_basics.cpp:40


geometric_shapes
Author(s): Ioan Sucan , Gil Jones
autogenerated on Fri Aug 20 2021 02:13:00