43 #include <gtest/gtest.h> 62 bool testIsometry3d(
const std::string&
id,
const Eigen::Isometry3d& expect,
const Eigen::Isometry3d& actual)
64 static const double EPSILON = 0.000001;
65 EXPECT_GT(EPSILON, fabs(expect.translation().x() - actual.translation().x()))
66 <<
id <<
" Translation x - expect: " << expect.translation().x() <<
" actual: " << actual.translation().x();
67 EXPECT_GT(EPSILON, fabs(expect.translation().y() - actual.translation().y()))
68 <<
id <<
" Translation y - expect: " << expect.translation().y() <<
" actual: " << actual.translation().y();
69 EXPECT_GT(EPSILON, fabs(expect.translation().z() - actual.translation().z()))
70 <<
id <<
" Translation z - expect: " << expect.translation().z() <<
" actual: " << actual.translation().z();
72 Eigen::Quaterniond q1(expect.rotation());
73 Eigen::Quaterniond q2(actual.rotation());
74 EXPECT_GT(EPSILON, fabs(q1.x() - q2.x())) <<
id <<
" Quaternion x - expect: " << q1.x() <<
" actual: " << q2.x();
75 EXPECT_GT(EPSILON, fabs(q1.y() - q2.y())) <<
id <<
" Quaternion y - expect: " << q1.y() <<
" actual: " << q2.y();
76 EXPECT_GT(EPSILON, fabs(q1.z() - q2.z())) <<
id <<
" Quaternion z - expect: " << q1.z() <<
" actual: " << q2.z();
77 EXPECT_GT(EPSILON, fabs(q1.w() - q2.w())) <<
id <<
" Quaternion w - expect: " << q1.w() <<
" actual: " << q2.w();
82 bool testVector(
const std::string&
id,
const std::vector<double>& expect,
const std::vector<double>& actual)
84 EXPECT_EQ(expect.size(), actual.size()) <<
id <<
" Unequal vector sizes";
86 static const double EPSILON = 0.000001;
87 for (std::size_t i = 0; i < expect.size(); ++i)
89 EXPECT_GT(EPSILON, fabs(expect[i] - actual[i])) <<
"Section " <<
id <<
", Element " << i
90 <<
", Expect: " << expect[i] <<
", Actual: " << actual[i];
117 Eigen::Isometry3d expected_affine = Eigen::Isometry3d::Identity();
118 std::vector<double> xyzrpy;
119 base.
visual_tools_->convertToXYZRPY(expected_affine, xyzrpy);
120 std::vector<double> expected_vector;
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 expected_vector.push_back(0);
127 EXPECT_TRUE(base.
testVector(
"Identity: ", expected_vector, xyzrpy));
131 EXPECT_TRUE(base.
testIsometry3d(
"Identity convert back", expected_affine, expected_affine2));
135 expected_affine.translation().x() = 1;
136 expected_affine.translation().y() = 2;
137 expected_affine.translation().z() = 3;
138 base.
visual_tools_->convertToXYZRPY(expected_affine, xyzrpy);
139 expected_vector[0] = 1;
140 expected_vector[1] = 2;
141 expected_vector[2] = 3;
142 EXPECT_TRUE(base.
testVector(
"123: ", expected_vector, xyzrpy));
146 EXPECT_TRUE(base.
testIsometry3d(
"123 convert back", expected_affine, expected_affine2));
149 expected_affine2 = base.
visual_tools_->convertFromXYZRPY(xyzrpy[0], xyzrpy[1], xyzrpy[2], xyzrpy[3], xyzrpy[4],
151 EXPECT_TRUE(base.
testIsometry3d(
"123 convert back long", expected_affine, expected_affine2));
154 expected_affine2 = base.
visual_tools_->convertFromXYZRPY(xyzrpy[0], xyzrpy[1], xyzrpy[2], xyzrpy[3], xyzrpy[4],
156 EXPECT_TRUE(base.
testIsometry3d(
"123 convert back new long", expected_affine, expected_affine2));
160 expected_affine = expected_affine * Eigen::AngleAxisd(M_PI, Eigen::Vector3d::UnitX()) *
161 Eigen::AngleAxisd(0.5 * M_PI, Eigen::Vector3d::UnitZ()) *
162 Eigen::AngleAxisd(-0.5 * M_PI, Eigen::Vector3d::UnitX());
163 base.
visual_tools_->convertToXYZRPY(expected_affine, xyzrpy);
167 EXPECT_TRUE(base.
testIsometry3d(
"123 convert back", expected_affine, expected_affine2));
170 expected_affine2 = base.
visual_tools_->convertFromXYZRPY(xyzrpy[0], xyzrpy[1], xyzrpy[2], xyzrpy[3], xyzrpy[4],
172 EXPECT_TRUE(base.
testIsometry3d(
"123 convert back long", expected_affine, expected_affine2));
175 expected_affine2 = base.
visual_tools_->convertFromXYZRPY(xyzrpy[0], xyzrpy[1], xyzrpy[2], xyzrpy[3], xyzrpy[4],
177 EXPECT_TRUE(base.
testIsometry3d(
"123 convert back new long", expected_affine, expected_affine2));
183 std::vector<geometry_msgs::Point> path1;
206 int main(
int argc,
char** argv)
208 testing::InitGoogleTest(&argc, argv);
209 ros::init(argc, argv,
"rviz_visual_tools_tests");
210 return RUN_ALL_TESTS();
int main(int argc, char **argv)
std::vector< Eigen::Vector3d, Eigen::aligned_allocator< Eigen::Vector3d > > vector_Vector3d
bool testIsometry3d(const std::string &id, const Eigen::Isometry3d &expect, const Eigen::Isometry3d &actual)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define ROS_INFO_STREAM_NAMED(name, args)
rviz_visual_tools::RvizVisualToolsPtr visual_tools_
TEST(RVTTest, initialize)
bool testVector(const std::string &id, const std::vector< double > &expect, const std::vector< double > &actual)
std::vector< Eigen::Isometry3d, Eigen::aligned_allocator< Eigen::Isometry3d > > vector_Isometry3d