43 #include <gtest/gtest.h> 
   61   bool testIsometry3d(
const std::string& 
id, 
const Eigen::Isometry3d& expect, 
const Eigen::Isometry3d& actual)
 
   63     static const double EPSILON = 0.000001;
 
   64     EXPECT_GT(EPSILON, fabs(expect.translation().x() - actual.translation().x()))
 
   65         << 
id << 
" Translation x - expect: " << expect.translation().x() << 
" actual: " << actual.translation().x();
 
   66     EXPECT_GT(EPSILON, fabs(expect.translation().y() - actual.translation().y()))
 
   67         << 
id << 
" Translation y - expect: " << expect.translation().y() << 
" actual: " << actual.translation().y();
 
   68     EXPECT_GT(EPSILON, fabs(expect.translation().z() - actual.translation().z()))
 
   69         << 
id << 
" Translation z - expect: " << expect.translation().z() << 
" actual: " << actual.translation().z();
 
   71     Eigen::Quaterniond q1(expect.rotation());
 
   72     Eigen::Quaterniond q2(actual.rotation());
 
   73     EXPECT_GT(EPSILON, fabs(q1.x() - q2.x())) << 
id << 
" Quaternion x - expect: " << q1.x() << 
" actual: " << q2.x();
 
   74     EXPECT_GT(EPSILON, fabs(q1.y() - q2.y())) << 
id << 
" Quaternion y - expect: " << q1.y() << 
" actual: " << q2.y();
 
   75     EXPECT_GT(EPSILON, fabs(q1.z() - q2.z())) << 
id << 
" Quaternion z - expect: " << q1.z() << 
" actual: " << q2.z();
 
   76     EXPECT_GT(EPSILON, fabs(q1.w() - q2.w())) << 
id << 
" Quaternion w - expect: " << q1.w() << 
" actual: " << q2.w();
 
   81   bool testVector(
const std::string& 
id, 
const std::vector<double>& expect, 
const std::vector<double>& actual)
 
   83     EXPECT_EQ(expect.size(), actual.size()) << 
id << 
" Unequal vector sizes";
 
   85     static const double EPSILON = 0.000001;
 
   86     for (std::size_t i = 0; i < expect.size(); ++i)
 
   88       EXPECT_GT(EPSILON, fabs(expect[i] - actual[i]))
 
   89           << 
"Section " << 
id << 
", Element " << i << 
", Expect: " << expect[i] << 
", Actual: " << actual[i];
 
  116   Eigen::Isometry3d expected_affine = Eigen::Isometry3d::Identity();
 
  117   std::vector<double> xyzrpy;
 
  119   std::vector<double> expected_vector;
 
  120   expected_vector.push_back(0);
 
  121   expected_vector.push_back(0);
 
  122   expected_vector.push_back(0);
 
  123   expected_vector.push_back(0);
 
  124   expected_vector.push_back(0);
 
  125   expected_vector.push_back(0);
 
  126   EXPECT_TRUE(
BASE.
testVector(
"Identity: ", expected_vector, xyzrpy));
 
  130   EXPECT_TRUE(
BASE.
testIsometry3d(
"Identity convert back", expected_affine, expected_affine2));
 
  134   expected_affine.translation().x() = 1;
 
  135   expected_affine.translation().y() = 2;
 
  136   expected_affine.translation().z() = 3;
 
  138   expected_vector[0] = 1;
 
  139   expected_vector[1] = 2;
 
  140   expected_vector[2] = 3;
 
  145   EXPECT_TRUE(
BASE.
testIsometry3d(
"123 convert back", expected_affine, expected_affine2));
 
  148   expected_affine2 = 
BASE.
visual_tools_->convertFromXYZRPY(xyzrpy[0], xyzrpy[1], xyzrpy[2], xyzrpy[3], xyzrpy[4],
 
  150   EXPECT_TRUE(
BASE.
testIsometry3d(
"123 convert back long", expected_affine, expected_affine2));
 
  153   expected_affine2 = 
BASE.
visual_tools_->convertFromXYZRPY(xyzrpy[0], xyzrpy[1], xyzrpy[2], xyzrpy[3], xyzrpy[4],
 
  155   EXPECT_TRUE(
BASE.
testIsometry3d(
"123 convert back new long", expected_affine, expected_affine2));
 
  159   expected_affine = expected_affine * Eigen::AngleAxisd(M_PI, Eigen::Vector3d::UnitX()) *
 
  160                     Eigen::AngleAxisd(0.5 * M_PI, Eigen::Vector3d::UnitZ()) *
 
  161                     Eigen::AngleAxisd(-0.5 * M_PI, Eigen::Vector3d::UnitX());
 
  166   EXPECT_TRUE(
BASE.
testIsometry3d(
"123 convert back", expected_affine, expected_affine2));
 
  169   expected_affine2 = 
BASE.
visual_tools_->convertFromXYZRPY(xyzrpy[0], xyzrpy[1], xyzrpy[2], xyzrpy[3], xyzrpy[4],
 
  171   EXPECT_TRUE(
BASE.
testIsometry3d(
"123 convert back long", expected_affine, expected_affine2));
 
  174   expected_affine2 = 
BASE.
visual_tools_->convertFromXYZRPY(xyzrpy[0], xyzrpy[1], xyzrpy[2], xyzrpy[3], xyzrpy[4],
 
  176   EXPECT_TRUE(
BASE.
testIsometry3d(
"123 convert back new long", expected_affine, expected_affine2));
 
  182   std::vector<geometry_msgs::Point> path1;
 
  206   using namespace Eigen;
 
  207   const auto x_actual = 
BASE.
visual_tools_->getVectorBetweenPoints(Vector3d::UnitX(), Vector3d::Zero());
 
  208   const auto x_expected =
 
  209       Isometry3d(Isometry3d::Identity()).translate(Vector3d::UnitX()).rotate(AngleAxisd(M_PI, Vector3d::UnitY()));
 
  210   EXPECT_TRUE(
BASE.
testIsometry3d(
"get_vector_between_points X", x_expected, x_actual));
 
  212   const auto x2_actual = 
BASE.
visual_tools_->getVectorBetweenPoints(2 * Vector3d::UnitX(), Vector3d::Zero());
 
  213   const auto x2_expected =
 
  214       Isometry3d(Isometry3d::Identity()).translate(2 * Vector3d::UnitX()).rotate(AngleAxisd(M_PI, Vector3d::UnitY()));
 
  215   EXPECT_TRUE(
BASE.
testIsometry3d(
"get_vector_between_points 2X", x2_expected, x2_actual));
 
  217   const auto random_actual = 
BASE.
visual_tools_->getVectorBetweenPoints({ 2.0, 3.0, 4.0 }, { 5.0, 6.0, 7.0 });
 
  218   const auto random_expected = []() {
 
  220     d << 0.57735, -0.211325, -0.788675, 2, 0.57735, 0.788675, 0.211325, 3, 0.57735, -0.57735, 0.57735, 4, 0, 0, 0, 1;
 
  221     return Eigen::Isometry3d(
d);
 
  223   EXPECT_TRUE(
BASE.
testIsometry3d(
"get_vector_between_points random", random_expected, random_actual));
 
  227 int main(
int argc, 
char** argv)
 
  229   testing::InitGoogleTest(&argc, argv);
 
  230   ros::init(argc, argv, 
"rviz_visual_tools_tests");
 
  231   return RUN_ALL_TESTS();